在docker容器内安装nfs共享

编程入门 行业动态 更新时间:2024-10-11 15:20:43
本文介绍了在docker容器内安装nfs共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 有没有人知道如何使用centos基本映像挂载docker容器内的nfs共享?我试过这个命令:

mount server:/ dir / mount / point

并得到下一个错误:

mount .nfs:rpc.statd没有运行,但是远程锁定是必需的。 mount.nfs:使用'-o nolock'来保持锁定本地或开始状态。 mount.nfs:指定了错误的挂载选项

当我尝试使用 -o nolock 选项时,错误是:

mount.nfs:不允许操作

解决方案

对于使用 mount ,您需要 CAP_SYS_ADMIN 功能,Docker在创建容器时将其删除。 / p>

有几种解决方案:

  • 使用 - privileged = true 标志。这会导致Docker不会丢弃任何功能,这些功能应该允许您从容器内装载NFS共享。这可能是一个安全问题;不要在不受信任的容器中执行此操作。
  • 将NFS共享挂载在主机上,并将其作为主机卷传递到容器中:

    你@主机> mount服务器:/ dir / path / to / mount / point 你@主机> docker运行-v / path / to / mount / point:/ path / to / mount / point

  • <

    使用Docker卷插件(如 Netshare 插件)直接安装NFS分享为容器卷:

    你@主机> docker运行\ --volume-driver = nfs \ -v server / dir:/ path / to / mount / point \ centos

    Does anyone know how to mount nfs share inside docker container with centos base image? I've tried this command:

    mount server:/dir /mount/point

    and got the next error:

    mount.nfs: rpc.statd is not running but is required for remote locking. mount.nfs: Either use '-o nolock' to keep locks local, or start statd. mount.nfs: an incorrect mount option was specified

    when I try to use it with -o nolock option, the error is:

    mount.nfs: Operation not permitted

    解决方案

    For using mount, you'll need the CAP_SYS_ADMIN capability, which is dropped by Docker when creating the container.

    There are several solutions for this:

  • Start the container with the --privileged=true flag. This causes Docker to not drop any capabilities, which should allow you to mount a NFS share from within the container. This might be a security issue; do not do this in untrusted containers.
  • Mount the NFS share on the host and pass it into the container as a host volume:

    you@host > mount server:/dir /path/to/mount/point you@host > docker run -v /path/to/mount/point:/path/to/mount/point

  • Use a Docker volume plugin (like the Netshare plugin) to directly mount the NFS share as a container volume:

    you@host > docker run \ --volume-driver=nfs \ -v server/dir:/path/to/mount/point \ centos

  • 更多推荐

    在docker容器内安装nfs共享

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

    发布评论

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

    >www.elefans.com

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