docker 安装nginx并挂载目录

docker 安装nginx并挂载目录

建立nginx挂载目录

mkdir /root/app/nginx/conf
mkdir /root/app/nginx/html
mkdir /root/app/nginx/log

创建临时nginx

docker run -d --name nginx-test nginx

拷贝容器的挂载文件

docker cp nginx-test:/etc/nginx/conf.d /root/app/nginx/conf

docker cp nginx-test:/etc/nginx/nginx.conf /root/app/nginx/conf/nginx.conf

docker cp nginx-test:/usr/share/nginx/html/index.html /root/app/nginx/html/index.html

删除临时nginx

docker rm -f nginx-test

创建挂载nginx

docker run -d -p 80:80 --name nginx \
-v /root/app/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /root/app/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /root/app/nginx/html/index.html:/usr/share/nginx/html/index.html \
-v /root/app/nginx/log:/var/log/nginx \
nginx

验证

访问你机器的ip,如192.168.1.123
因为端口是80,所以可以默认不加端口号

重新加载nginx

docker exec -it nginx <指令>

docker exec -it nginx nginx -s reload

你可能感兴趣的:(docker,nginx,docker,运维)