docker中使用nginx
宿主机和docker中nginx做映射
宿主机中nginx 映射目录 /root/myDockerData/devnginx
在容器中相关位置分别是:
配置文件位置:/etc/nginx/
日志位置:/var/log/nginx/
项目位置:/usr/share/nginx/html
如下配置启动命令行,即可开启宿主机和docker中nginx的文件映射
docker run --name mynginx
-v /root/myDockerData/devnginx/conf/nginx.conf:/etc/nginx/nginx.conf
-v /root/myDockerData/devnginx/conf.d:/etc/nginx/conf.d
-v /root/myDockerData/devnginx/log:/var/log/nginx
-v /root/myDockerData/devnginx/html:/usr/share/nginx/html
-p 8081:80 -d nginx
整理成一行
docker run --name mynginx -v /root/myDockerData/devnginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /root/myDockerData/devnginx/conf.d:/etc/nginx/conf.d -v /root/myDockerData/devnginx/log:/var/log/nginx -v /root/myDockerData/devnginx/html:/usr/share/nginx/html -p 8081:80 -d nginx
在宿主机中修改配置文件后,重新加载配置文件。(一般修改 /root/myDockerData/devnginx/conf.d 中的 default.conf )
docker exec mynginx nginx -s reload
或者
docker exec -it mynginx nginx -s reload
或者
docker exec -it mynginx /bin/bash
nginx -s reload