How to mount nfs share from docker container?
9,105
You probably need to run your containers in privileged mode:
docker run --privileged=true
If you can upgrade docker to 17.06, you can mount a NFS share directly, without extra capabilities:
docker run --mount 'type=volume,src=src_name,volume-driver=local,dst=/mnt,volume-opt=type=nfs,volume-opt=device=:/nfs-share,"volume-opt=o=nfs-server,vers=4,hard,timeo=600,rsize=1048576,wsize=1048576,retrans=2"' -d -it --name mycontainer ubuntu
Got the hint from the discussion here: https://github.com/moby/moby/issues/28809
Related videos on Youtube
![fredrik](https://i.stack.imgur.com/EbI9j.jpg?s=256&g=1)
Author by
fredrik
Updated on September 18, 2022Comments
-
fredrik almost 2 years
I can see the shares of the server:
[root@sandbox /]# showmount -e 192.168.0.111 Export list for 192.168.0.111: /RAIDPOOL02/vers * /RAIDPOOL02/prod * /RAIDPOOL02/pipeline *
When I attempt to mount, I get this:
[root@sandbox /]# mkdir -p /192.168.0.111/pipeline [root@sandbox /]# mount --verbose --options=nolock,exec,soft,intr,uid=500,rsize=65536,wsize=65536 192.168.0.111:/pipeline /192.168.0.111/pipeline mount.nfs: timeout set for Wed May 4 08:16:49 2016 mount.nfs: trying text-based options 'nolock,soft,intr,uid=500,rsize=65536,wsize=65536,vers=4,addr=192.168.0.111,clientaddr=172.20.0.3' mount.nfs: mount(2): Operation not permitted mount.nfs: trying text-based options 'nolock,soft,intr,uid=500,rsize=65536,wsize=65536,addr=192.168.0.111' mount.nfs: prog 100003, trying vers=3, prot=6 mount.nfs: trying 192.168.0.111 prog 100003 vers 3 prot TCP port 2049 mount.nfs: prog 100005, trying vers=3, prot=17 mount.nfs: trying 192.168.0.111 prog 100005 vers 3 prot UDP port 20048 mount.nfs: mount(2): Operation not permitted mount.nfs: Operation not permitted
I'm exposing these ports in my Dockerfile:
EXPOSE 2049 EXPOSE 20048
And I can successfully nmap port 2049 of the server:
[root@sandbox /]# nmap -p 2049 192.168.0.111 Starting Nmap 6.40 ( http://nmap.org ) at 2016-05-04 08:21 UTC Nmap scan report for 192.168.0.111 Host is up (0.00061s latency). PORT STATE SERVICE 2049/tcp open nfs
Why am I getting "Operation not permitted"?