在docker容器内安装nfs共享 [英] Mounting nfs shares inside docker container
问题描述
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共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!