How to mount NFS shares with Docker

Prior to Docker 17 you had to mount an NFS share to a host before mounting it to a container. This is problematic if the container isn’t dedicated to a single host. In this tutorial, I will show you how to mount an NFS share directly to a running container.

The solution for mounting NFS shares isn’t eloquent, but if you have experience working work NFS then it will be very familiar to you.

The options we provide are the same used by other tools and utilities to mount shared volumes.

docker run --mount 'type=volume,src=VOL_NAME,volume-driver=local,dst=/LOCAL-MNT,volume-opt=type=nfs,volume-opt=device=:/NFS-SHARE,"volume-opt=o=addr=NFS-SERVER,vers=4,hard,timeo=600,rsize=1048576,wsize=1048576,retrans=2"' -d -it ubuntu