# 1. 拉取 nginx
sudo docker pull nginx
# 2. 创建目录
sudo mkdir -p /home/docker/nginx/conf /home/docker/nginx/html /home/docker/nginx/log
# 3. 生成容器,将其文件复制到物理机
docker run --name nginx -p 9001:80 -d nginx
# 将容器nginx.conf文件复制到宿主机
sudo docker cp nginx:/etc/nginx/nginx.conf /home/docker/nginx/conf/nginx.conf
# 将容器conf.d文件夹下内容复制到宿主机
sudo docker cp nginx:/etc/nginx/conf.d /home/docker/nginx/conf/conf.d
# 将容器中的html文件夹复制到宿主机
sudo docker cp nginx:/usr/share/nginx/html /home/docker/nginx/
# 4. 删除生成的nginx容器
sudo docker rm -f nginx
# 5. 重新生成nginx容器,并进行挂载
sudo docker run \
-p 9002:80 \
--name nginx \
-v /home/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /home/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
-v /home/docker/nginx/log:/var/log/nginx \
-v /home/docker/nginx/html:/usr/share/nginx/html \
-d nginx:latest
标签:nginx,sudo,Nginx,html,conf,home,Docker,docker
From: https://www.cnblogs.com/WTAGO/p/18324975