Docker

無法將 NFS 掛載到容器

  • October 21, 2019

我需要為我的 k8s 集群設置一個 NFS 伺服器。我可以設置它並將其安裝到在裸機 ubuntu 上執行的客戶端,但是當我嘗試將 NFS 安裝到容器(客戶端是 ubuntu 18.04 容器)時,它會失敗並出現以下錯誤:

$ mount 10.203.20.160:/var/nfs/general /nfs/general
mount: /nfs/general: cannot mount 10.203.20.160:/var/nfs/general read-only.

$ mount 10.203.20.160:/var/nfs/general /nfs/general --rw
mount: /nfs/general: 10.203.20.160:/var/nfs/general is write-protected but explicit read-write mode requested.

$ mount 10.203.20.160:/var/nfs/general /nfs/general --ro
mount: /nfs/general: cannot mount 10.203.20.160:/var/nfs/general read-only.

我確信伺服器配置是正確的,因為正如我所說,如果我在裸機上,我可以安裝,但我不知道為什麼當我在容器內時它會失敗。

我的伺服器配置:

  • NFS 目錄訪問權限:
$ ls -la /var/nfs/general
total 8
drwxr-xr-x 2 777 nogroup 4096 Oct 21 10:00 .
drwxr-xr-x 3 777 root    4096 Oct 21 10:00 ..
  • /etc/出口:
$ cat /etc/exports
/var/nfs/general *(rw,sync,no_subtree_check,no_root_squash)

按照官方指南,很好地解釋如何將 NFS 連接到 kubernetes 中的容器:https ://docs.docker.com/ee/ucp/kubernetes/storage/use-nfs-volumes/

引用自:https://serverfault.com/questions/988831