I’m putting this here because I just spent upwards of half my day search through this forum/github/and other sites.
How to use nfs mounts in docker container?
I put my answer up, any input from more experienced users is greatly appreciated.
Share and learn in the Docker community.
I’m putting this here because I just spent upwards of half my day search through this forum/github/and other sites.
How to use nfs mounts in docker container?
I put my answer up, any input from more experienced users is greatly appreciated.
In a simplistic fashion, nfs mounts can be achieved by a compose file like this:
version: "3.5"
services:
builder:
image: my_build
volumes:
- "nfsmountCC:/opt/" # nfsmountCC is the volume created by docker-compose in the volumes section below. /opt/ is the mount location inside of the container.
volumes:
nfsmountCC:
driver: local
driver_opts:
type: nfs
o: addr=10.90.239.72 # IP of nfs server. This is also where you put any options '-o' in standard option format
device: ":/opt/compilers/" # location on nfs server of file/dir you want to mount
Obviously remove the ‘#’ comments… they are for explanation only
I really hope this helps somebody. I had issues with finding the starting point, it seemed everyone had a different way of doing this simple task.
and here provides the syntax for not using compose
@sdetweil
Thanks for the post, I will say I saw that SO post and the compose example gave me errors. I did not try the others. could have been due to some settings I have though.
This has really helped me. I cannot thank you enough. Surprisingly difficult to find an answer to this through general googling (probably using the wrong search terms tbf).
Does this allow you to mount multiple directories?
i.e. if I specify “:/volume1/Download :/volume1/Music” etc will that mount those directories correctly? Or do I need to add seperate ‘device’ entries?
Thanks for any help!
My guess is you will need separate devices, but I do not know. I am doing some docker-compose testing this week so I’ll see if I can test.
hello,
There are several solutions for this:
Start the container with the --privileged=true flag. This causes Docker to not drop any capabilities, which should allow you to mount a NFS share from within the container. This might be a security issue; do not do this in untrusted containers.
Mount the NFS share on the host and pass it into the container as a host volume:
you@host > mount server:/dir /path/to/mount/point
you@host > docker run -v /path/to/mount/point:/path/to/mount/point
Use a Docker volume plugin (like the Netshare plugin) to directly mount the NFS share as a container volume:
you@host > docker run
–volume-driver=nfs
-v server/dir:/path/to/mount/point
centos