如何在Docker容器中安装

编程入门 行业动态 更新时间:2024-10-20 06:34:36
本文介绍了如何在Docker容器中安装 - 绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这个容器基于 debian:jessie (但这并不是很相关,因为我与 alpine相同的问题:3.3 )。我到达了我需要的地步。

I have this container based on debian:jessie (but this is not very relevant as I had the same issue with alpine:3.3). I get to the point where I need to

mount --bind /htdocs/www /home/user/example/www

我得到

mount: permission denied

我在任何内核日志中找不到任何东西,而 -vvv 没有什么有趣的。我显然可以在主机上(与任何其他子树/节点对)进行此操作。在我上面的例子中,/ htdocs / www是Docker卷的挂载点,但它似乎并不重要,因为我不能 mount --bind

I can't find anything in any kernel log, and -vvv yields nothing interesting. 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.

推荐答案

使用 mount 系统调用,您需要 CAP_SYS_ADMIN 功能。默认情况下,Docker在产生容器时删除所有功能(这意味着即使使用 root ,您也不能做任何事情)。有关详细信息,请参阅 mount(2)手册页。

For using the mount system call, you need the CAP_SYS_ADMIN capability. By default, Docker drops all capabilities when spawning a container (meaning that even as root, you're not allowed to do everything). See the mount(2) man page for more information.

您可以使用 - cap-add = SYS_ADMIN 标志启动容器,以将此功能添加到容器中:

You can start your container with the --cap-add=SYS_ADMIN flag to add this capability to your container:

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.

更多推荐

如何在Docker容器中安装

本文发布于:2023-10-07 15:14:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469736.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   如何在   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!