NFS connection pattern for docker containers

For anyone using FreeNAS or similar where files are shared out via NFS, connecting multiple docker containers can be a bit tricky when multiple containers need to access the same NFS volumes.

Passing on the NFS connection pattern that I use:

#!/usr/bin/env bash
# create and run sonarr container with FreeNAS


sudo docker run \
    --name=sonarr \
    -e PUID=1000 \
    -e PGID=1000 \
    -e TZ=Europe/London \
    -e UMASK_SET=022 `#optional` \
    -p 8989:8989 \
    -v /home/docker/sonarr/config:/config \
    --mount type=volume,dst=/downloads,volume-driver=local,volume-opt=type=nfs,\"volume-opt=o=nfsvers=4,addr=${NAS}\",volume-opt=device=:${NAS_DOWNLOAD} \
    --mount type=volume,dst=/tv,volume-driver=local,volume-opt=type=nfs,\"volume-opt=o=nfsvers=4,addr=${NAS}\",volume-opt=device=:${NAS_SERIES} \
    --restart unless-stopped \

Create an nfs docker volume and map that volume into containers

per aptalca’s comment, it should look something like

      type: "nfs"
      o: "addr=192.168.0.XXX,nolock,hard,rw,retrans=2,wsize=1048576,rsize=1048576,nfsvers=4.1"
      device: ":/docker/storage/"

i couldn’t be more precise because you, for some reason, blanked out a non-routable non-unique ip address :slight_smile:

if you can’t support nfs4.1 just remove the version line from options

Now try scaling to multiple concurrent containers and see where that takes you. Let us know how that works out for you. :grinning:

I don’t follow… i use this setup across 27 containers right now, it works fine and is our recommended method of presenting nfs storage to a docker container.

Right, but you’re using (nolock,rw). So scaling may be simple, but it can be ineffective on shared files and folders. If you trust everyone to keep separate, NP. It’s just less robust in some use cases. How does scaling work with (lock, rw)?

As well, you may have full control over all of your settings and well-behaved users/apss, so this pattern is just something else. For Mandalorians, I guess “This is the way”. :grinning:

I gave you an example and said “something like this” obviously you would adjust it to fit your needs…

the whole point was, you didnt know how to pass nfs into docker properly, we told you how and provided an example. This isn’t really the proper place to be a troll.

Actually, I’m a bit offended that when I offered a different connection pattern than the volume pattern that I’m getting razzed for it. The docker volume pattern is fine if that’s what you need, but there are other safe ways to do nfs connects.

Nice welcome to the community, driz.