docker compose 卷的文件权限不正确? 13:权限被拒绝

发布于 2025-01-12 19:31:16 字数 2152 浏览 2 评论 0原文

我有以下 docker_compose.yaml:

version: "3.8"

services:
  reverse-proxy:
    image: nginx:1.17.10
    container_name: reverse_proxy
    volumes:
      - ../nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "8050:8050"
      - "8051:8051"
  webapp:
    image: my-site
    command: --port 8050 8051 --debug yes
    volumes:
      - /home/user/data:/data
    ports:
      - "8050:8050"
      - "8051:8051"
    depends_on:
      - reverse-proxy

当我通过 docker compose 运行时,出现以下错误:

$ sudo docker-compose -f /home/user/docker_compose.yaml up
...
reverse_proxy    | 2022/03/09 00:49:19 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
reverse_proxy    | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
reverse_proxy exited with code 1

因此为了调查,我重新运行了 nginx 容器:

$ sudo docker run -v ../nginx/nginx.conf:/etc/nginx/nginx.conf -t docker.io/nginx tail -f /dev/null

ssh'd我明白了:

root@d8e84f89fcad:/# ls -la /etc/nginx/
ls: cannot access '/etc/nginx/nginx.conf': Permission denied
total 20
drwxr-xr-x. 3 root root  132 Mar  1 14:00 .
drwxr-xr-x. 1 root root   66 Mar  9 00:54 ..
drwxr-xr-x. 2 root root   26 Mar  1 14:00 conf.d
-rw-r--r--. 1 root root 1007 Jan 25 15:03 fastcgi_params
-rw-r--r--. 1 root root 5349 Jan 25 15:03 mime.types
lrwxrwxrwx. 1 root root   22 Jan 25 15:13 modules -> /usr/lib/nginx/modules
-?????????? ? ?    ?       ?            ? nginx.conf
-rw-r--r--. 1 root root  636 Jan 25 15:03 scgi_params
-rw-r--r--. 1 root root  664 Jan 25 15:03 uwsgi_params

我咨询了以下问题和其他人和他们似乎建议重新启动 docker 服务,所以我这样做了,并且在重新运行时我仍然获得 ? 权限。

我认为这导致了权限错误?如果是这样,我如何在此 nginx 配置文件上设置正确的权限?这真的是卷权限问题吗?

版本:

Docker version 1.13.1, build 7d71120/1.13.1
docker-compose version 1.29.2, build 5becea4c
CentOS 7

I have the following docker_compose.yaml:

version: "3.8"

services:
  reverse-proxy:
    image: nginx:1.17.10
    container_name: reverse_proxy
    volumes:
      - ../nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "8050:8050"
      - "8051:8051"
  webapp:
    image: my-site
    command: --port 8050 8051 --debug yes
    volumes:
      - /home/user/data:/data
    ports:
      - "8050:8050"
      - "8051:8051"
    depends_on:
      - reverse-proxy

When I run via docker compose I get the following error:

$ sudo docker-compose -f /home/user/docker_compose.yaml up
...
reverse_proxy    | 2022/03/09 00:49:19 [emerg] 1#1: open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
reverse_proxy    | nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (13: Permission denied)
reverse_proxy exited with code 1

So to investigate I re-ran just the nginx container:

$ sudo docker run -v ../nginx/nginx.conf:/etc/nginx/nginx.conf -t docker.io/nginx tail -f /dev/null

ssh'd in and I see:

root@d8e84f89fcad:/# ls -la /etc/nginx/
ls: cannot access '/etc/nginx/nginx.conf': Permission denied
total 20
drwxr-xr-x. 3 root root  132 Mar  1 14:00 .
drwxr-xr-x. 1 root root   66 Mar  9 00:54 ..
drwxr-xr-x. 2 root root   26 Mar  1 14:00 conf.d
-rw-r--r--. 1 root root 1007 Jan 25 15:03 fastcgi_params
-rw-r--r--. 1 root root 5349 Jan 25 15:03 mime.types
lrwxrwxrwx. 1 root root   22 Jan 25 15:13 modules -> /usr/lib/nginx/modules
-?????????? ? ?    ?       ?            ? nginx.conf
-rw-r--r--. 1 root root  636 Jan 25 15:03 scgi_params
-rw-r--r--. 1 root root  664 Jan 25 15:03 uwsgi_params

I consulted the following Q and others and they seem to suggest to just restart the docker service, so I did and I still get ? permissions upon re running.

I assume that this is causing the permission error? If so, how can I set the correct permissions on this nginx config file? Is this really a volume permission issue?

Versions:

Docker version 1.13.1, build 7d71120/1.13.1
docker-compose version 1.29.2, build 5becea4c
CentOS 7

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2025-01-19 19:31:16

我认为这是 SELinux 的问题,将 :z 附加到卷修复了它。

volumes:
      - ../nginx/nginx.conf:/etc/nginx/nginx.conf:z

I think it was an SELinux thing, appending :z to the volume fixed it.

volumes:
      - ../nginx/nginx.conf:/etc/nginx/nginx.conf:z
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文