1.拉取镜像:
docker pull nginx
2.创建挂在路径:
mkdir -p /usr/local/nginx/conf
mkdir -p /usr/local/nginx/logs
mkdir -p /usr/local/nginx/www
mkdir -p /usr/local/nginx/conf.d
3.启动镜像:为了拿到位置文件,先启动下
docker run --name nginx -p 80:80 -d nginx
4.复制容器中的配置文件到挂载目录
docker cp nginx:/etc/nginx/nginx.conf /usr/local/nginx/conf
docker cp nginx:/etc/nginx/conf.d/default.conf /usr/local/nginx/conf.d
5.扩展操作:停止nginx并删除
docker stop nginx
docker -rm nginx
6.编辑nginx配置文件
vi /usr/local/nginx/conf.d/default.conf
# 编辑完成,按esc,输入: :wq,退出
7.启动nginx容器
docker run -d -p 80:80 --name nginx-web --privileged=true --restart=always -v /usr/local/nginx/www:/usr/share/nginx/html -v /usr/local/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/nginx/logs:/var/log/nginx nginx