So, you’d like to create a docker volume that is an NFS client?
The Docker documentation doesn’t state that this is possible, but it actually is! I’ll show you how:
Creating the NFS (client) volume
docker volume create \ --driver local \ --opt type=nfs \ --opt device=:/absolute/path/on/nfs/server \ --opt o=addr=127.0.0.1,rw,nfsvers=4 \ --name my-nfs-volume
This should give you a Docker volume, with the name
my-nfs-volume, you can of course change
--name in the above command to your liking.
Make sure to replace
/absolute/path/on/nfs/server with the actual path as is on the server.
Lastly, don’t forget to replace
127.0.0.1 with the actual server address of your NFS server.
Using the volume
When using docker run, you can use it like any other volume, with:
Of course, changing the volume name and mount point to your volume name and actual path required.
In the above command to create the volume, you can remove
,rw to instead get a read-only volume. Furthermore, you can remove
,nfsvers=4 to instead get a volume that uses NFSv3.
The best part is, this volume is now persistent, you can stop/start your containers, remove and recreate them, and always point to that volume. Docker will remember the connection parameters for
my-nfs-volume (or whatever you named it).
Further, you can re-run the volume create command, changing parameters, to replace the volume with the new parameters. This is useful when you might change NFS server address, for example. But make sure to stop and remove your containers that use the volume, first!
That’s all there is to it!
I run this blog in my free time, if it helped you, consider linking to it or donating a coffee. (:
Leave A Comment