在 Docker 上安装 Nfs

install nfs in docker

1. create share directory used by nfs

1
mkdir -p /home/ooooo/shared/nfs

2. create exports.txt used by nfs

This the exports.txt mainly used to mount dir (path in the container ) and permission.

for example:

It indicates read only for all ip.

1
2
vim /home/ooooo/exports.txt
/home/ooooo/shared/nfs             *(ro,no_subtree_check)

3. execute docker command

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
docker run -d                                         \
  -v /home/ooooo/shared/nfs:/home/ooooo/shared/nfs    \
  -v /home/ooooo/exports.txt:/etc/exports:ro          \
  --cap-add SYS_ADMIN                                 \
  -p 2049:2049                                        \
  erichough/nfs-server
  
# check nfs server
netstat -nla | grep 2049

# mount nfs dir (check mount.nfs whether is exist )
# 172.17.0.2 is container ip
mount 172.17.0.2:/home/ooooo/shared/nfs /home/ooooo/nfs-mount

5. 参考

docker images

0%