在 docker 容器内挂载 nfs 共享 [英] Mounting nfs shares inside docker container
本文介绍了在 docker 容器内挂载 nfs 共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道如何使用 centos 基础映像在 docker 容器内挂载 nfs 共享?我试过这个命令:
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 没有运行,但是远程锁定需要.
mount.nfs:要么使用'-o nolock'来保持本地锁,或者启动statd.
mount.nfs: 指定了错误的安装选项
当我尝试将它与 -o nolock 选项一起使用时,错误是:
when I try to use it with -o nolock option, the error is:
mount.nfs: Operation not permitted
推荐答案
从docker 17.06开始,运行时可以直接挂载NFS共享到容器,不需要额外的能力
Starting from docker 17.06, you can mount NFS shares to the container directly when you run it, without the need of extra capabilities
export NFS_VOL_NAME=mynfs
export NFS_LOCAL_MNT=/mnt/mynfs
export NFS_SERVER=my.nfs.server.com
export NFS_SHARE=/my/server/path
export NFS_OPTS=vers=4,soft
docker run --mount
"src=$NFS_VOL_NAME,dst=$NFS_LOCAL_MNT,volume-opt=device=:$NFS_SHARE,"volume-opt=o=addr=$NFS_SERVER,$NFS_OPTS",type=volume,volume-driver=local,volume-opt=type=nfs"
busybox ls $NFS_LOCAL_MNT
或者,您可以在容器之前创建卷:
Alternatively, you can create the volume before the container:
docker volume create
--driver local
--opt type=nfs
--opt o=addr=$NFS_SERVER,$NFS_OPTS
--opt device=:$NFS_SHARE
$NFS_VOL_NAME
docker run --rm -v $NFS_VOL_NAME:$NFS_LOCAL_MNT busybox ls $NFS_LOCAL_MNT
- 得到提示https://github.com/moby/moby/issues/28809
- 来自 docker 的官方文档:https://docs.docker.com/storage/volumes/#create-a-service-which-creates-an-nfs-volume
这篇关于在 docker 容器内挂载 nfs 共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文