简体   繁体   English

将卷挂载到 sudo 无权访问的 docker

[英]Mount volume to docker to which sudo does not have access

I am trying to mount a volume into docker on a compute cluster running ubuntu 18.04.我正在尝试在运行 ubuntu 18.04 的计算集群上将卷安装到 docker 中。 This volume is on a mounted filesystem to which my user has access, but sudo does not.此卷位于我的用户可以访问的已安装文件系统上,但 sudo 没有。 I do have sudo permissions on this cluster.我在这个集群上确实有 sudo 权限。 I use this command:我使用这个命令:

docker run -it --mount type=bind,source="$(pwd)"/logs,target=/workspace/logs tmp:latest bash

The result is this error:结果是这个错误:

docker: Error response from daemon: invalid mount config for type "bind": stat /home/logs: permission denied.
See 'docker run --help'.

Mounting the volume works fine on my local machine where both sudo and I have access to the drive I want to mount, which makes me believe that the problem is indeed that on the server sudo does not have permissions to the drive I want to mount into docker.在我的本地机器上挂载卷工作正常,我和 sudo 都可以访问我想要挂载的驱动器,这让我相信问题确实是服务器上的 sudo 没有我想要挂载的驱动器的权限docker。

What I have tried:我试过的:

  • running the post-install steps $ sudo groupadd docker && sudo usermod -aG docker $USER运行安装后步骤$ sudo groupadd docker && sudo usermod -aG docker $USER

  • running docker with sudo使用sudo运行 docker

  • running docker with --privileged使用 --privileged 运行--privileged

  • running docker with --user $(id -u):$(id -g)使用--user $(id -u):$(id -g)运行 docker

  • setting the user inside the dockerfile with USER $(id -u):$(id -g) (plugging in the actual values)使用USER $(id -u):$(id -g)在 dockerfile 中设置用户(插入实际值)

Is there a way to mount the volume in this setup or to change the dockerfile to correctly access the drive with my personal user?有没有办法在此设置中安装卷或更改 dockerfile 以使用我的个人用户正确访问驱动器? Any help would be much appreciated.任何帮助将非常感激。

On a sidenote, within docker I would only require readaccess to the volume in case that changes anything.在旁注中,在 docker 中,我只需要对卷进行读取访问,以防发生任何更改。

The container is created by the Docker daemon, which runs as root.该容器由 Docker 守护进程创建,该守护进程以 root 身份运行。 That's why it still doesn't work even if you run the container or the docker command as your own user.这就是为什么即使您以自己的用户身份运行容器或docker命令,它仍然无法工作的原因。

You might be able to run the daemon as your own user (rootless mode).您可能能够以自己的用户身份运行守护程序(无根模式)。

You could also look at changing the mount options (on the host system) so that the root user on the host does have access.您还可以查看更改挂载选项(在主机系统上),以便主机上的root用户确实具有访问权限。 How to do this depends on the type of filesystem.如何做到这一点取决于文件系统的类型。

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

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