[英]How do I mount --bind inside a Docker container?
I have this container based on debian:jessie
(but this is not very relevant as I had the same issue with alpine:3.3
).我有这个基于
debian:jessie
的容器(但这不是很相关,因为我对alpine:3.3
有同样的问题)。 I get to the point where I need to我到了我需要的地方
mount --bind /htdocs/www /home/user/example.com/www
and I get我得到
mount: permission denied
I can't find anything in any kernel log, and -vvv
yields nothing interesting.我在任何内核日志中都找不到任何东西,并且
-vvv
没有产生任何有趣的东西。 I obviously can do this on the host (with any other pair of subtree/node).我显然可以在主机上执行此操作(使用任何其他子树/节点对)。 In my example above /htdocs/www is the mountpoint of a Docker volume, but it doesn't appear like it's of any importance, as I can't
mount --bind
any pair of subtree/node inside the container.在我上面的示例中,/htdocs/www 是 Docker 卷的挂载点,但它看起来并不重要,因为我无法在容器内
mount --bind
任何一对子树/节点。
For using the mount
system call, you need the CAP_SYS_ADMIN
capability.要使用
mount
系统调用,您需要CAP_SYS_ADMIN
功能。 By default, Docker drops all capabilities when spawning a container (meaning that even as root , you're not allowed to do everything).默认情况下,Docker 在生成容器时会删除所有功能(这意味着即使作为root ,您也不能做任何事情)。 See the mount(2) man page for more information.
有关更多信息,请参阅mount(2) 手册页。
You can start your container with the --cap-add=SYS_ADMIN
flag to add this capability to your container:您可以使用
--cap-add=SYS_ADMIN
标志启动容器以将此功能添加到您的容器中:
root@host > docker run --rm -it --cap-add=SYS_ADMIN debian:jessie
root@ee0b1d5fe546:/# mkdir /mnt/test
root@ee0b1d5fe546:/# mount --bind /home /mnt/test/
root@ee0b1d5fe546:/#
Use this with caution .请谨慎使用。 Do not run untrusted software in a privileged container.
不要在特权容器中运行不受信任的软件。
Try with --privileged
flag:尝试使用
--privileged
标志:
docker run --rm -it --privileged=true debian
mkdir /mnt/test
mount --bind /home /mnt/test/
I was searching some info's for Docker/Kubernetes to give capabilities permission, and found some informations我正在搜索 Docker/Kubernetes 的一些信息以授予功能权限,并找到了一些信息
docker run --rm -it --security-opt apparmor:unconfined --cap-add=SYS_ADMIN debian:jessie
mkdir /mnt/test
mount --bind /home /mnt/test/
would help.有助于。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.