赞
踩
[Unit]
Description=Docker Service
Documentation=https://docs.docker.com
After=network.target
[Service]
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375
Restart=always
StartLimitIntervalSec=0
[Install]
WantedBy=multi-user.target
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache
sudo yum install docker-ce
若依官网 https://www.ruoyi.vip/
选择前后端分离版本
# 基础镜像 FROM java:openjdk-8u111-jre # 维护者信息 MAINTAINER zj # 设置容器时区为当前时区 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone # /tmp 目录作为容器数据卷目录,SpringBoot内嵌Tomcat容器默认使用/tmp作为工作目录,任何向 /tmp 中写入的信息不会记录进容器存储层 # 在宿主机的/var/lib/docker目录下创建一个临时文件并把它链接到容器中的/tmp目录 VOLUME /tmp # 复制主机文件至镜像内,复制的目录需放置在 Dockerfile 文件同级目录下 ADD ./ruoyi-admin/target/ruoyi-admin.jar ruoyi-admin.jar # 容器启动执行命令 ENTRYPOINT ["java", "-Xmx128m","-Djava.security.egd=file:/dev/./urandom", "-jar", "/ruoyi-admin.jar"] # 声明容器提供服务端口 EXPOSE 8080
mkdir -p /usr/local/mysql/data /usr/local/mysql/conf.d
docker run --name mysql --restart=always --privileged=true \
-v /usr/local/mysql/data:/var/lib/mysql \
-v /usr/local/mysql/conf.d:/etc/mysql/conf.d \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 -d mysql:latest
# 进入容器内部
docker exec -it mysql /bin/bash
# mysql -u root -p
# 选择数据库
show databases;
use mysql;
# 修改连接权限
ALTER USER root@'%' IDENTIFIED WITH mysql_native_password BY '123456';
ALTER USER root@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
-- 刷新权限
FLUSH PRIVILEGES;
docker run -d -p 6379:6379 --name redis --restart always redis:latest
mkdir -p /home/docker/nginx/html /home/docker/nginx/conf /home/docker/nginx/log
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; #前端项目的端口 server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } location /prod-api/{ proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://39.100.94.212:8080/; #后台项目的运行端口 } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
docker run --restart always --name nginx8888 --volume "/home/docker/nginx/html":/usr/share/nginx/html --volume "/home/docker/nginx/conf/nginx.conf":/etc/nginx/nginx.conf -p 8888:80 -d nginx
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。