Difficulty: Advanced
What are Docker volume drivers, and when would you use something other than the default local driver?
A volume driver decides where and how a Docker volume's data is actually stored. The built-in local driver keeps data in a directory under /var/lib/docker/volumes on the host (and can also mount NFS or CIFS shares), while third-party volume plugins let a volume live on networked or cloud storage so it can outlive the host and follow a container to another machine.
When you run docker volume create -d <driver> data, Docker calls the driver's API (Create, Mount, Unmount, Remove, Path). On container start, Docker asks the driver to mount the volume and gets back a host path, which it then bind-mounts into the container. The container never knows whether the bytes are on a local SSD, an NFS server or a cloud block device. That separation is the whole point: application code writes to /var/lib/postgresql/data and the storage decision is made by whoever runs the platform.
The local driver accepts mount options that map to the Linux mount command, so for many teams it is enough:
--opt type=nfs --opt o=addr=10.0.1.5,rw,nfsvers=4 --opt device=:/exports/uploads mounts an NFS export.--opt type=cifs mounts an SMB share (credentials go in o=).--opt type=tmpfs --opt device=tmpfs --opt o=size=100m creates an in-memory volume.The mount happens when the first container using the volume starts, so a wrong IP or a firewalled NFS port shows up as a container start error, not a volume create error.
Third-party drivers are installed as managed plugins, for example docker plugin install vieux/sshfs, and then used with -d vieux/sshfs. Vendors such as Portworx and NetApp have shipped Docker volume plugins for their storage. In practice:
| Situation | Typical choice |
|---|---|
| Single host, database or cache data | local named volume on fast disk |
| Several hosts or Swarm services sharing files | local with NFS options, or a vendor plugin |
| Kubernetes cluster | Not Docker volume drivers at all; Kubernetes uses CSI drivers (EBS CSI, EFS CSI, and so on) |
| Throwaway scratch data | tmpfs mount |
The Kubernetes row matters in interviews: since Kubernetes moved to containerd and CSI, Docker volume plugins are mainly a Docker Engine and Swarm concern. Saying "on EKS we would use the EBS CSI driver with a PersistentVolumeClaim" shows you know where each abstraction lives.
# Create a named volume that mounts an NFS export when first used
docker volume create \
--driver local \
--opt type=nfs \
--opt o=addr=10.0.1.5,rw,nfsvers=4 \
--opt device=:/exports/uploads \
uploads
# Any container (on any host with the same volume definition) sees the shared files
docker run -d --name web -v uploads:/app/uploads myorg/web:2.1
docker volume inspect uploads --format '{{.Driver}} {{json .Options}}'
No plugin is needed for NFS; the local driver passes these options to the kernel mount call when the volume is first mounted.
services:
web:
image: myorg/web:2.1
volumes:
- uploads:/app/uploads
volumes:
uploads:
driver: local
driver_opts:
type: nfs
o: "addr=10.0.1.5,rw,nfsvers=4"
device: ":/exports/uploads"
Compose creates the volume with these driver options on first up. Changing driver_opts later requires removing and recreating the volume.
Volume plugins, local driver, NFS mounts, docker volume create, Persistent storage, CSI