brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a Docker volume can mount an NFS share with the local driver

Docker
~/tips/tip-docker-volume-nfs-driver-opts

docker volume create --driver local \

Creates a Docker volume that mounts a share from your NAS over NFS, no plugin needed.

You do not need a volume plugin to put container data on a NAS. Docker’s built-in local driver takes mount options, and NFS is one of them. This is the example from the Docker docs:

docker volume create --driver local \
  --opt type=nfs \
  --opt o=addr=192.168.1.1,rw \
  --opt device=:/path/to/dir \
  foo

type is the filesystem, o is a comma-separated list of mount options with the server address, and device is the export path, with the colon in front. Use the volume like any other with -v foo:/data, and Docker mounts the share when a container needs it.

In a compose file it looks like this:

volumes:
  media:
    driver: local
    driver_opts:
      type: "nfs"
      o: "addr=192.168.1.10,nolock,soft,rw"
      device: ":/export/media"

The compose docs show the driver_opts part. I add driver: local myself so it is clear which driver gets the options.

Caveats. The docs say the local driver takes options like the Linux mount command on Linux and Docker Desktop, and no options at all on Windows. The host needs NFS client support. And the options are stored when the volume is created: change the address later and you have to remove and recreate the volume. Permissions are the usual NFS story, so the user inside the container needs access on the NAS side.

Further reading: docker volume create reference, Compose file reference: volumes

More Docker tips ONBUILD RUN /usr/local/bin/python-build --dir /app/src SHELL ["/bin/bash", "-c"] docker commit <container> myname/testimage:version3 docker import /path/to/exampleimage.tgz docker compose events All Docker tips (192) All topics

Link