Mounting NFS Shares as Docker Volumes

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

Replace 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. rsize and 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.


  1. Somehow, this dosen’t work unfrtunately (Raspi 4, Docker 19.03.10).. What am I doing wrong? The Volume itself works correctly and can be mounted with mount.

    docker volume create –driver local –opt type=nfs4 –opt o=addr=,rw –opt device=:/volume1/dockervol foo

    docker run -p 8005:80 -v foo:/config –name bitwarden –restart always bitwardenrs/server:raspberry

    docker: Error response from daemon: error while mounting volume ‘/var/lib/docker/volumes/foo/_data’: failed to mount local volume: mount :/volume1/dockervol:/var/lib/docker/volumes/foo/_data, data: addr= protocol not supported.
    ERRO[0005] error waiting for container: context canceled

Leave a Reply

Your email address will not be published.