docker 官方nginx镜像 不能挂载/etc/nginx/nginx.conf

#docker run -p 80:80 --name mynginx -v $PWD/html:/www -v $PWD/nginx.conf:/etc/nginx/nginx.conf -v $PWD/logs:/wwwlogs  -d nginx
#docker logs mynginx 

open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (13: Permission denied)

root@oracledb nginx]#  docker run -i -t nginx /bin/bash
root@2c21f58950df:/# cd /etc/nginx/
root@2c21f58950df:/etc/nginx# ls -l
total 32
drwxr-xr-x. 2 root root   25 Jul 26 07:33 conf.d
-rw-r--r--. 1 root root 1007 Jul 11 13:06 fastcgi_params
-rw-r--r--. 1 root root 2837 Jul 11 13:06 koi-utf
-rw-r--r--. 1 root root 2223 Jul 11 13:06 koi-win
-rw-r--r--. 1 root root 3957 Jul 11 13:06 mime.types
lrwxrwxrwx. 1 root root   22 Jul 11 13:06 modules -> /usr/lib/nginx/modules
-rw-r--r--. 1 root root  643 Jul 11 13:06 nginx.conf
-rw-r--r--. 1 root root  636 Jul 11 13:06 scgi_params
-rw-r--r--. 1 root root  664 Jul 11 13:06 uwsgi_params
-rw-r--r--. 1 root root 3610 Jul 11 13:06 win-utf
阅读 16.5k
3 个回答
✓ 已被采纳新手上路,请多包涵

新的镜像没有这个问题了。

#!/bin/bash
docker run --name=mynginx -p 80:80 \
        --restart=always \
        -v /home/tomcat/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
    -v /home/tomcat/nginx/conf.d:/etc/nginx/conf.d \
    -v /home/tomcat/nginx/www:/usr/share/nginx/html \
    -v /home/tomcat/nginx/logs:/var/log/nginx \
    -d nginx

--privileged=true

都提示了是没有权限造成的,那就排查下权限。看看宿主机本地的nginx.confother用户是否有读权限,再排查下该配置文件的所有父级目录是否有访问权限。或者像一楼说的用docker run --privileged=true启动容器,这样就是使用root用户权限了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进