1、拉取镜像
docker pull nginx:1.21.4
2、创建目录
mkdir -p /opt/nginx/{html,logs}
chmod 777 /opt/nginx/{html,logs}
3、增加配置文件
(1)先随便启动nginx容器,用于复制配置文件
docker run -p 80:80 --name nginx -d nginx:1.21.4
(2)进入待存放nginx配置的目录下
cd /opt/nginx
(3)将容器内文件复制到当前目录
docker container cp nginx:/etc/nginx /opt/nginx
(4)将nginx重命名为config
mv nginx config
chmod 7777 config
(5)查看config文件夹
cd /opt/nginx/config
ls
(3)删除容器
docker rm -f nginx
4、启动容器
docker run -p 80:80 --name nginx --restart=always \
-v /opt/nginx/config:/etc/nginx \
-v /opt/nginx/html:/usr/share/nginx/html \
-v /opt/nginx/logs:/var/log/nginx \
-d nginx:1.21.4