docker部署项目是老生常谈的话题了。此文仅供给从未部署过的开发者查阅
- 安装docker,这个自行百度。参考链接https://www.runoob.com/docker/centos-docker-install.html
- 基于docker安装nginx镜像,docker pull nginx
- 运行docker容器,docker run -p 8090:80 --name ng -d nginx
- 创建nginx配置和日志文件目录等
-
- mkdir -p /opt/nginx/conf/conf.d
- mkdir -p /opt/nginx/log
- mkdir -p /opt/nginx/html
- 将容器里面的配置文件复制一份到主机上
-
- docker cp ng:/etc/nginx/conf.d /opt/nginx/conf/conf.d
- docker cp ng:/usr/share/nginx/html /opt/nginx/
- 停止原容器和并删除
-
- docker stop ng
- docker rm -f ng
- 启动新容器携带逻辑卷
-
- docker run -p 8090:80 --name ng -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/nginx/conf/conf.d:/etc/nginx/conf.d -v /opt/nginx/log:/var/log/nginx -v /opt/nginx/html:/usr/share/nginx/html -d nginx
- 直接访问 8090即可得到数据。
- 如果想该代理修改主机的/opt/nginx目录下的相关文件,然后重复6-7步骤即可