Mounting NFS shares to docker containers allows me to access files on my NAS with applications such as NextCloud, SyncThing, Duplicati, and Plex. I prefer to mount NFS shares as docker volumes but the command to run is a little different than your typical
docker volume create command.
My NAS uses NFS4 so the command below is set up to connect to a device that supports NFS4. Below is the code you can use:
docker volume create --name VOLUME_NAME --driver local \ --opt type=nfs4 \ --opt o=addr=HOST_ADDRESS,rw,noatime,rsize=8192,wsize=8192,tcp,timeo=14 \ --opt device=:YOUR/NFS/PATH
VOLUME_NAME with the name of the volume that you would like to create. Replace
HOST_ADDRESS with the IP address of the system that your NFS server.
noatime is included to ensure a reduced disk IO by not recording the time that files have been accessed.
wsize determine the size of the individual data chunks. These settings work well with my Synology NAS.
tcp specifies to connect via TCP and
timeo is how long before the connection times out if the NFS server does not respond.
The final variable that you need to replace is
:YOUR/NFS/PATH. It is very important to leave the
: at the beginning of the path otherwise docker will not be able to successfully connect.
I created a folder in my NAS called
DockerVol and inside that folder are various folders for all of my docker containers. I created a separate docker volume for each of those folders. This is a good way to keep docker volumes centralized so they can be accessed from outside of the docker container if necessary. It has truly been a “set it and forget it” way of storing persistent volumes for my docker containers.