我有这个图像,我从主机安装一个卷
-v /Users/john/workspace:/data/workspace
在容器内部,我使用的是不同于root的用户.现在问题是它无法在/ data / workspace内创建/修改文件(权限被拒绝).现在我解决了它现在在主机上做chmod -R 777工作区. Docker解决这个问题的方法是什么?
解决方法:
Managed to solve this using the new dockerfile args. It doesn’t require doing anything special after the container is built, so I thought I’d share. (Requires Docker 1.9)
In the 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)
这样,容器中的用户可以写入已安装的主机卷(无需chown / chmod)
标签:docker,linux,permissions
来源: https://codeday.me/bug/20190609/1202068.html