简体   繁体   English

如何创建具有非root用户访问权限和docker-compose的共享卷?

[英]How can I create a shared volume with non-root access rights and docker-compose?

Before I decided that it is probably a good idea to run the web service not as root in its Docker container, I simply had 在我决定不以root身份运行Web服务可能是一个好主意之前,我已经

version: '3'
services:
  web:
    build: .
    ...
    volumes:
     - .:/opt/app  # enables hot code reloading
     - uploads:/opt/app/uploads         
  ...
volumes:
    uploads:
        driver: local

in order to have the folder /opt/app/uploads within the client being identical to the uploads folder on the host. 为了使客户端中的文件夹/opt/app/uploads与主机上的uploads文件夹相同。

Now, having added a new non-root user, I see the problem that the volume directory /opt/app/uploads gets assigned to the root, not to the user. 现在,添加了新的非root用户后,我看到了将卷目录/opt/app/uploads分配给root而不是用户的问题。

How can I fix that? 我该如何解决?

(I know that I can access the container and do it manually ... but I would like to know if there is a simpler solution; eg editing the Dockerfile or the docker-compose.yml ) (我知道我可以访问容器并手动进行操作……但是我想知道是否有更简单的解决方案;例如,编辑Dockerfiledocker-compose.yml

Was rather simple: Add the following line to the Dockerfile . 非常简单: Dockerfile添加到Dockerfile Make sure the directory has the rights you want. 确保目录具有所需的权限。

RUN mkdir -p /opt/app/uploads

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为非root用户创建Docker-compose卷 - Docker-compose volume creation for non-root user (EACCES: permission denied, mkdir '/usr/app/node_modules/.cache) 如何创建一个 docker-compose 文件来使 node_modules 成为非根文件夹? - (EACCES: permission denied, mkdir '/usr/app/node_modules/.cache) How can I create a docker-compose file to make node_modules a non-root folder? 如何在docker中以非root用户身份写入卷容器? - How do I write to a volume container as non-root in docker? 我希望Docker非root用户能够写入持久卷吗? 我怎样才能解决这个问题? - I want a Docker non-root user to be able to write to a persistent volume? How can I fix this? 如何在使用docker-compose和非root用户时将node_modules保留在容器中? - How to keep node_modules inside container while using docker-compose and a non-root user? 如何在 docker-compose 中使用共享卷 - How to use a shared volume in docker-compose docker 无法使用非 root 用户写入已安装的卷 - docker can not write on mounted volume with non-root user 如何让 Docker 容器中的非 root 用户访问安装在主机上的卷 - How to give non-root user in Docker container access to a volume mounted on the host 如何在Docker容器中为非root用户设置卷权限 - How to set volume permission in docker container for non-root user tomcat docker-compose 无法访问共享卷 - tomcat docker-compose cannot access to shared volume
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM