+-

参见英文答案 > Share files between host system and docker container using specific UID 4个
我正在使用Docker(1.3.1)在容器内构建RPM:
我正在使用Docker(1.3.1)在容器内构建RPM:
docker run -v /home/matt/build:/build build-rpm /build/build-pkg.sh
这工作正常(我的用户在docker组中,因此我不需要sudo)并在当前目录中删除已完成的.rpm文件.问题是该文件是由root拥有的.
我如何安排它,以便创建文件由我运行docker的同一用户拥有?
最佳答案
您可以尝试创建(在自定义映像的Dockerfile中)用户并将其设置为容器使用的用户
RUN adduser --system --group --shell /bin/sh auser \
&& mkdir /home/auser/bin
USER auser
然后检查docker是否运行-v / home / matt / build:/ build build-rpm将/ build中的共享文件夹挂载为auser.
issue 2259中提到的另一个选项:
If you
chownthe volume (on the host side) before bind-mounting it, it will work.
In that case, you could do:
mkdir /tmp/www
chown 101:101 /tmp/www
docker run -v /tmp/www:/var/www ubuntu stat -c "%U %G" /var/www
(Assuming that
101:101is theUID:GIDof thewww-datauser in your container.)
点击查看更多相关文章
转载注明原文:Docker在挂载的卷中以root身份创建文件 - 乐贴网