docker 部署 nginx镜像启动失败 外加一些常用操作

今天在docker里部署nginx遇到一个坑,如下:
[emerg] “user” directive is not allowed here in /etc/nginx/conf.d/nginx.conf:2

# 直接运行nginx 镜像
docker run -d -p 80:80 --name nginx_1 \
-v /opt/nginx/project:/usr/share/nginx/html \
-v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx/logs:/var/log/nginx \
-v /opt/nginx/cache:/var/cache/nginx/ \
--privileged=true nginx
# 查看镜像,结果镜像没有起来
docker ps
# 查看日志
docker logs 126d58471a08
# 错误结果说是 nginx.conf 的错误
[emerg] "user" directive is not allowed here in /etc/nginx/conf.d/nginx.conf:2

解决方法:

# 先跑一个
docker run --name nginx_2 -d nginx
# 将它里的配置文件复制到想要映射的位置
docker cp 126d58471a08:/etc/nginx/nginx.conf /opt/nginx/conf/
# 删掉之前的nginx 镜像,重新创建
docker run -d -p 80:80 --name nginx_1 \
-v /opt/nginx/project:/usr/share/nginx/html \
-v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /opt/nginx/logs:/var/log/nginx \
-v /opt/nginx/cache:/var/cache/nginx/ \
--privileged=true nginx

我这里有个想法,就不实验了,复制好了配置文件,直接启动之前的没有起来的镜像,看看是不是也可以,这样就省的重新 删除创建了,感兴趣的小伙伴可以试试.

后记

到此为止镜像已经成功起来,下面记录一些常用操作

# 进入系统
docker exec -it 126d58471a08 /bin/bash
# 检查配置⽂件
nginx -t
# 重新载⼊配置⽂件
nginx -s reload
# 重启 Nginx
nginx -s reopen 
# 停⽌ Nginx
nginx -s stop
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值