编写DockerFile文件
# 镜像nginx
FROM nginx
# 作者
MAINTAINER ZhangBin# 将前端dist文件中的内容复制到镜像的nginx目录
COPY dist /usr/share/nginx/html/# 用本地的nginx配置文件覆盖镜像的Nginx配置
COPY nginx.conf /etc/nginx/conf.d/default.confEXPOSE 80
编写nginx.conf文件
server{listen 80;server_name 192.168.192.135;location / {add_header Cache-Control "no-cache";root /usr/share/nginx/html/;index index.html index.htm;try_files $uri $uri/ /index.html;}location /prod-api/ {proxy_pass http://192.168.192.135:8086/;client_max_body_size 100M;client_body_buffer_size 256k;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}
将dist文件夹、DockerFile文件、nginx.conf文件放在同一个目录下,并打包成一个镜像
docker build -t ruoyi .
运行容器
docker run -d -p 8088:80 --name ruoyis ruoyi