1、下载
docker pull nginx:latest
2、本地创建管理目录
- mkdir -p /var/docker/nginx/conf
- mkdir -p /var/docker/nginx/log
- mkdir -p /var/docker/nginx/html
3、将容器中的相应文件复制到管理目录中 /usr/docker/nginx
- docker run --name nginx -p 80:80 -d nginx
-
- docker cp nginx:/etc/nginx/nginx.conf /var/docker/nginx/conf/nginx.conf
- docker cp nginx:/etc/nginx/conf.d /var/docker/nginx/conf/conf.d
- docker cp nginx:/usr/share/nginx/html /var/docker/nginx/
4、停止并移除容器
- docker stop 容器ID
- docker rm 容器ID
5、再次启动容器并作目录挂载
- docker run \
- -p 80:80 \
- --name nginx \
- --privileged=true \
- -v /var/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
- -v /var/docker/nginx/conf/conf.d:/etc/nginx/conf.d \
- -v /var/docker/nginx/log:/var/log/nginx \
- -v /var/docker/nginx/html:/usr/share/nginx/html \
- -d nginx
6、测试