1.下载nginx镜像到docker
# docker pull nginx
2.拷贝临时容器默认文件到默认路径
# docker cp nginx-container:/etc/nginx/nginx.conf /usr/local/docker/nginx/nginx.conf
# docker cp -a nginx-container:/usr/share/nginx/html /usr/local/docker/nginx
# docker cp nginx-container:/etc/nginx/conf.d /usr/local/docker/nginx/conf.d
3.进入/usr/local/docker/nginx/conf.d下,在conf.d文件中
# cd /usr/local/docker/nginx/conf.d
# vi conf.d
添加后端路径端口映射:
location /api/ {
proxy_pass http://127.0.0.1:8081/;
}
4.删除临时容器
# docker rm -f nginx-container
5.删除/usr/local/docker/nginx/html目录下的文件,并将前端打包的dist文件中所有文件拷贝到/usr/local/docker/nginx/html目录下
6.重新映射容器启动一个nginx容器
# docker run --name hbcomponent-frontend -e TZ="Asia/Shanghai" -d -p 8080:80 -v /usr/local/docker/nginx/html:/usr/share/nginx/html -v /usr/local/docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx/conf.d:/etc/nginx/conf.d -v /usr/local/docker/nginx/logs:/var/log/nginx nginx