使用docker部署nginx最佳实践
创建挂载目录
bash
复制代码
mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
运行容器
bash
复制代码
docker run --name nginx -d -p 80:80 nginx
复制nginx默认配置
bash
复制代码
docker cp nginx:/etc/nginx/nginx.conf /home/nginx/nginx.conf
docker cp nginx:/etc/nginx/conf.d /home/nginx/conf.d
docker cp nginx:/usr/share/nginx/html /home/nginx/html
docker rm -f nginx
重新运行nginx镜像
bash
复制代码
docker run --name nginx -m 200m -p 80:80 \
-v /home/nginx/nginx.conf:/etc/nginx/nginx.conf \
-v /home/nginx/conf.d:/etc/nginx/conf.d \
-v /home/nginx/html:/usr/share/nginx/html \
-v /home/nginx/log:/var/log/nginx \
-e TZ=Asia/Shanghai \
--restart=always \
--privileged=true -d nginx
# -e TZ=Asia/Shanghai:设置时区
# --restart=always: 保持自动重启
# --privileged=true: 获取root权限启动容器