从外部主机挂载Dockerized NFS共享

时间:2017-02-20 12:13:24

标签: ubuntu docker nfs

我有一个Dockerized nfs-kernel-server,它基于我发现的Dockerfile和脚本here

在我的Ubuntu主机中,我可以使用接口docker0的IP地址来安装卷。

$ sudo mount -v -t nfs 172.17.0.2:/srv/nfs /mnt

mount.nfs: timeout set for Mon Feb 20 12:57:14 2017
mount.nfs: trying text-based options 'nfsvers=3,addr=172.17.0.2'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: trying 172.17.0.2 prog 100003 vers 3 prot TCP port 2049
mount.nfs: prog 100005, trying vers=3, prot=17
mount.nfs: trying 172.17.0.2 prog 100005 vers 3 prot UDP port 33602

当我尝试使用我的公共IP进行安装时(即使是从我的主机系统),它表示权限被拒绝:

$ sudo mount -v -t nfs 192.168.120.153:/srv/nfs /mnt

mount.nfs: timeout set for Mon Feb 20 12:57:03 2017
mount.nfs: trying text-based options 'vers=4,addr=192.168.120.153,clientaddr=192.168.120.153'
mount.nfs: mount(2): Permission denied
mount.nfs: access denied by server while mounting 192.168.120.153:/srv/nfs

当我尝试使用NFS v3时,我得到了这个:

$ sudo mount -v -t nfs -o nfsvers=3 192.168.120.153:/srv/nfs /mnt

mount.nfs: timeout set for Mon Feb 20 12:49:48 2017
mount.nfs: trying text-based options 'nfsvers=3,addr=192.168.120.153'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: portmap query retrying: RPC: Program not registered
mount.nfs: prog 100003, trying vers=3, prot=17
mount.nfs: portmap query failed: RPC: Program not registered
mount.nfs: requested NFS version or transport protocol is not supported

由于共享已经可以安装,我假设它是访问/权限问题而不是服务问题。这个问题背后可能是什么原因?

--- --- EDIT

以下运行命令更改错误消息:

docker run -d --privileged \
--name nfs \
-p 2049:2049/tcp \
-p 2049:2049/udp \
-p 111:111/tcp \
-p 111:111/udp \
-p 1066:1066/tcp \
-p 1067:1067/tcp \
-p 1067:1067/udp \
-v /tmp:/srv/nfs \
cpuguy83/nfs-server /srv/nfs

尝试使用v3或v4进行安装现在会产生相同的错误消息:

mount.nfs: mount(2): No such file or directory
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

我没有运行防火墙,我已经检查过rpcbind正在我的主机系统上运行。当我尝试-o nolock选项时,我得到以下内容:

mount.nfs: trying text-based options 'nolock,nfsvers=3,addr=192.168.120.153'
mount.nfs: prog 100003, trying vers=3, prot=6
mount.nfs: portmap query retrying: RPC: Unable to receive
mount.nfs: prog 100003, trying vers=3, prot=17
mount.nfs: portmap query failed: RPC: Unable to receive - Connection refused

1 个答案:

答案 0 :(得分:1)

由于您没有提供您使用的docker run命令行,我假设您使用了链接的Github存储库中的示例:

docker run -d --name nfs --privileged cpuguy83/nfs-server /path/to/share /path/to/share2 /path/to/shareN

这导致NFS端口不被暴露,因此只能通过专用docker IP访问。请尝试:

docker run -d --name nfs --privileged -p 111:111/udp -p 2049:2049 cpuguy83/nfs-server /path/to/share /path/to/share2 /path/to/shareN

重要的部分是-p 111:111/udp -p 2049:2049

在此之后,您应该能够使用公共IP安装它。

请注意,您可能必须先删除旧容器:

docker rm -f nfs