[英]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
) (我知道我可以访问容器并手动进行操作……但是我想知道是否有更简单的解决方案;例如,编辑
Dockerfile
或docker-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.