首先拉取nginx
docker pull nginx
创建nginx文件夹、logs文件夹
mkdir /nginx
mkdir /nginx/logs
将vue打包好的dist文件夹上传至刚刚创建的nginx文件夹
进入nginx文件夹
cd /nginx
创建nginx.conf
touch nginx.conf
nginx.conf的中的内容为
try_files $uri $uri/ /index.html;防止页面刷新出现404错误
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; try_files $uri $uri/ /index.html; } } }
最后,启动容器
docker run -d -p 80:80 --name nginx \
-v /nginx/dist:/usr/share/nginx/html \
-v /nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /nginx/logs:/var/log/nginx \
--restart=always nginx
访问,由于容器使用80端口启动,即可以直接通过linux的ip访问