[英]Docker Compose Shared Named Volume Permissions Denied
The following docker-compose spins up containers for a Django application:以下 docker-compose 为 Django 应用程序启动容器:
version: '3.7'
services:
web:
build:
context: .
dockerfile: Dockerfile.prod
container_name: web
volumes:
- static_volume:/static
- media_volume:/media
...
nginx:
container_name: nginx
build: ./nginx_proxy
restart: always
volumes:
- static_volume:/static
- media_volume:/media
...
volumes:
media_volume:
static_volume:
The web container is built using the following Dockerfile: web 容器是使用以下 Dockerfile 构建的:
# pull official base image
FROM python:3.8
...
# organise permissions
RUN chown -R manager:manager /static
RUN chmod -R 755 /static
RUN chown -R manager:manager /media
RUN chmod -R 755 /media
RUN ls -la
...
When the permissions are printed as web container is being built, it returns the following:当权限打印为 web 容器正在构建时,它返回以下内容:
Step 21/23 : RUN ls -la
---> Running in e61984edfbcb
total 1760
drwxr-xr-x 1 manager:manager 4096 Jan 25 00:00 media
drwxr-xr-x 1 manager:manager 4096 Jan 25 00:00 static
Removing intermediate container e61984edfbcb
As expected and set in the Dockerfile.正如预期的那样,在 Dockerfile 中设置。
BUT when the containers are spun up (docker-compose up) and I look inside the permissions of the web container, I find the following:但是当容器旋转起来(docker-compose up)并且我查看 web 容器的权限时,我发现以下内容:
docker exec -it web bash
manager@c8762586f678:/$ ls -la
total 1760
drwxrwxr-x 3 root:root 4096 Sep 22 11:12 media
drwxr-xr-x 3 manager:manager 4096 Sep 22 11:12 static
Why do the two named volumes have different permissions - specifically, why is the media volume reverted to root:root?为什么两个命名卷具有不同的权限 - 具体来说,为什么媒体卷恢复为 root:root? How can I ensure that the media volume has the same permissions as the static folder inside the web container?
如何确保媒体卷与 web 容器内的 static 文件夹具有相同的权限?
Thanks in advance提前致谢
Hi hope you are doing great嗨,希望你做得很好
I managed the same issue tonight and i found a solution by adding我今晚解决了同样的问题,我通过添加找到了解决方案
sudo chown -R user-you-want:user-you-want data/**
I think i managed to install docker using sudo and forgetting to give the right to my actual user我想我设法使用 sudo 安装 docker 并忘记将权利授予我的实际用户
Hope it helps:D希望它有帮助:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.