docker部署nginx
1.拉取nginx docker pull nginx 默认最新的
2.使用docker images查看下载下来的镜像文件
3.创建宿主机的挂载目录
①nginx的配置文件mkdir -p /home/nginx/conf
②nginx的默认配置文件 mkdir -p /home/nginx/conf.d
③nginx显示的htmlmkdir -p /home/nginx/html
④nginx的日志文件mkdir -p /home/nginx/logs
4.启动nginxdocker run -d --name nginx -p 80:80 nginx
①把容器里的默认配置文件复制出来
docker cp nginx:/etc/nginx/conf.d/default.conf /home/nginx/conf.d/
②把容器里的主配置文件复制出来
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/
③关闭容器docker kill nginx
④移除容器docker rm nginx
5.在nginx/html目录下添加一个index.html内容可以自己写,也可以百度
Welcome to nginx! Welcome to nginx!
hello world
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
6.先确认服务器是否放行该端口:8080
docker run --name nginx -e TZ="Asia/Shanghai" -d -p 8080:80 -v /home/nginx/html:/usr/share/nginx/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx -v /home/nginx/conf.d:/etc/nginx/conf.d -d nginx
看不懂命令的,去看Docker基础原理和命令
着重强调一下-e TZ="Asia/Shanghai"不添加的话,就是默认的utc时间,和北京时间差8小时
**需要代理https的要加上 ** -v /home/nginx/ssl/:/ssl/ 里面放置ssl证书
7.启动之后,输入服务器地址+端口号就可以看到
8.当你修改配置文件之后,需要重启容器 docket restart 容器id/容器名



