Docker Community Forums

Share and learn in the Docker community.

How to mount nfs drive in container: simplest way

(Scarlson) #1

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.

Error while mounting volume with options: type='nfs'
(Scarlson) #2

In a simplistic fashion, nfs mounts can be achieved by a compose file like this:

version: “3.5”

    image: my_build
      - "nfsmountCC:/opt/"    # nfsmountCC is the volume created by docker-compose in the volumes section below.  /opt/ is the mount location inside of the container.
    driver: local
      type: nfs
      o: addr=       # 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.

(Sam) #3

and here provides the syntax for not using compose

(Scarlson) #4

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.

(Stool) #5

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!

(Scarlson) #6

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.

(Craigomez) #7

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
-v server/dir:/path/to/mount/point
Tutuapp TextNow Photomath

(Sohiniyadav9895) #8

“Error uploading file northstar4c.png. There was no response from the server. Check your network connection, and try again. If this problem persists, try again later.”

Note that it always stops exactly at 60% complete, no matter if I remove that PNG file, rearrange it, rename it, etc. This is my sixth iteration of the site, and have never had trouble uploading before.