Docker & NFSv4

Updated

Remember, a few hours of trial and error can save you several minutes of looking at the README.

With that out of the way, this is how I store my container data, running on an application server, on my network attached storage device.

Below is based on my experimental Nextcloud setup at home1. I’m storing all data on my TrueNAS machine using NFSv4 as my local drive is quite small.

# docker-compose.yml
version: '3.2'
services:
  whatever:
    image: what/ever:latest
    volumes:
      - type: volume
        source: container-data
        target: /var/www/html/data
        volume:
          nocopy: true
# [...]
volumes:
  container-data:
    driver: local
    driver_opts:
      type: "nfs4"
      o: "addr=192.168.0.1,rw,nfsvers=4,async"
      device: ":/remote/path/to/data"

The relevant section of the volume documentation is here.


  1. Setup once, played around with it a bit, and never bothered to put it into production or remove it. ↩︎