简体   繁体   English

Docker:已安装卷的权限

[英]Docker: Permissions for a mounted volume

I have this image in which I mount a volume from the host 我有这个图像,我从主机安装一个卷

-v /Users/john/workspace:/data/workspace

Inside the container I'm using a user different than root. 在容器内部,我使用的是不同于root的用户。 Now the problem is that it cannot create/modify files inside /data/workspace (permission denied). 现在问题是它无法在/data/workspace内创建/修改文件(权限被拒绝)。 Now I solved it for now to do chmod -R 777 workspace on the host. 现在我解决了它现在在主机上做chmod -R 777 workspace What would be the docker way to solve this ? Docker解决这个问题的方法是什么?

This might be solved with user mapping (issue 7198) , but that same thread include: 这可以通过用户映射来解决(问题7198) ,但同一个线程包括:

Managed to solve this using the new dockerfile args. 管理使用新的dockerfile args解决这个问题。 It doesn't require doing anything special after the container is built, so I thought I'd share. 在容器构建之后它不需要做任何特殊的事情,所以我想我会分享。 (Requires Docker 1.9) (需要Docker 1.9)

In the Dockerfile: 在Dockerfile中:

# Setup User to match Host User, and give superuser permissions
ARG USER_ID=0
RUN useradd code_executor -u ${USER_ID} -g sudo
RUN echo 'code_executor ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
USER ${USER_ID} 

Then to build: 然后建立:

docker build --build-arg USER_ID=$(id -u)

That way, the user in the container can write in the mounted host volume (no chown/chmod required) 这样,容器中的用户可以写入已安装的主机卷(无需chown / chmod)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM