Lesson 94 · Section 8: Storage
Lesson 94: Volume driver plugins in Docker: volumes beyond the local disk
Who actually creates and mounts a Docker volume: the built-in local driver, what it can do with NFS, and third-party plugins that put a volume on network or cloud storage. The idea that Kubernetes later standardised as CSI. · 13 min read · 4 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
What this lesson is about
In the previous lesson a volume was a directory under /var/lib/docker/volumes. That protects data from
docker rm, but not from a broken disk, and it ties the data to one host. If the container is started on another
machine, the volume there is empty.
Real systems keep data on storage that is independent of any single host: an NFS server, a cloud disk, a storage cluster. Docker reaches such storage through volume drivers. This lesson shows what a volume driver is, what the built-in one can already do, and how third-party plugins extend it.
You will not install Docker plugins on a Kubernetes cluster, and the CKA exam does not ask you to. The lesson is here because the idea, storage as a pluggable driver selected by name, is exactly what the Container Storage Interface, storage classes and PersistentVolumes are built on.
Two kinds of driver
Docker has two unrelated plug-in points for storage, and their names are easy to mix up.
| Storage driver | Volume driver | |
|---|---|---|
| Manages | Image layers and the container's writable layer | Volumes |
| Examples | overlay2, containerd snapshotters such as overlayfs | local, plus plugins |
| Chosen | Once per daemon, in the daemon configuration | Per volume, with --driver |
| Chosen by | The host's operating system and file system | Where you want the data to live |
| Data survives the container | No | Yes |
Parts:
- Container db (MySQL)
- Storage driver (overlay2 or overlayfs)
- Volume driver (local, or a plugin)
- Layers (image + container layer)
- Volume data (disk, NFS, cloud disk)
Connections:
- Container db to Storage driver: /
- Container db to Volume driver: /var/lib/mysql
- Storage driver to Layers: stores
- Volume driver to Volume data: stores
A storage driver question is about layers and copy-on-write. A volume driver question is about where persistent data is kept.
The local driver
Every volume records which driver owns it:
docker volume create data_volume
docker volume ls
docker volume inspect data_volume
DRIVER VOLUME NAME
local data_volume
[
{
"CreatedAt": "2026-12-02T10:14:03Z",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/data_volume/_data",
"Name": "data_volume",
"Options": null,
"Scope": "local"
}
]
local is built into the daemon. With no options it creates a directory under /var/lib/docker/volumes. With
options it does something more useful: it runs a mount for you each time a container starts using the volume,
and unmounts when the last container stops. The options are those of the Linux mount command.
| Option | Meaning | Example |
|---|---|---|
type | File system type | nfs, cifs, tmpfs, ext4 |
device | What to mount | :/exports/db, //server/share, /dev/sdb1 |
o | Mount options, comma separated | addr=10.0.0.10,rw,nfsvers=4 |
An NFS share as a Docker volume, with nothing extra installed in Docker:
docker volume create --driver local \
--opt type=nfs \
--opt o=addr=10.0.0.10,rw,nfsvers=4 \
--opt device=:/exports/db \
nfs-db
docker run -d --name db -e MYSQL_ROOT_PASSWORD=pw \
--mount type=volume,source=nfs-db,target=/var/lib/mysql mysql:8.4
Create the same volume definition on a second host, and a container there sees the same files, because the data is on the NFS server and not on either host.
Volume plugins
For storage that a plain mount cannot reach, such as a cloud disk that must first be created through an API and
attached to the virtual machine, Docker offers a plugin interface. A volume plugin is a program, written by a
storage vendor or the community, that implements a small API. Docker calls it whenever it needs a volume.
Plugins exist or have existed for many systems:
| Storage | Plugins (examples) |
|---|---|
| Cloud block storage (AWS EBS, Azure Disk, Google Persistent Disk) | REX-Ray, vendor plugins |
| Cloud and network file shares | Azure File Storage plugin, NetApp Trident, vieux/sshfs |
| Distributed storage | GlusterFS, Portworx, Flocker, Convoy |
| Many cloud and remote back ends | rclone |
Installing and using a plugin
Modern plugins are distributed as images in a registry and managed with docker plugin:
docker plugin install --grant-all-permissions vieux/sshfs
docker plugin ls
ID NAME DESCRIPTION ENABLED
ac720b8fcfdb vieux/sshfs:latest sshFS plugin for Docker true
Then the plugin's name is the driver, and --opt (short -o) carries options that only this plugin understands:
docker volume create --driver vieux/sshfs \
-o sshcmd=backup@10.0.0.20:/srv/data \
-o password=secret \
ssh-data
docker run --rm -v ssh-data:/data alpine:3.22 ls /data
You can also create the volume and start the container in one command. There are two spellings:
# --mount carries the driver and its options
docker run -d --name db \
--mount type=volume,volume-driver=vieux/sshfs,source=ssh-data,target=/data,volume-opt=sshcmd=backup@10.0.0.20:/srv/data,volume-opt=password=secret \
alpine:3.22 sleep 3600
# -v with --volume-driver: the driver name only, no options
docker run -d --name db2 --volume-driver vieux/sshfs -v ssh-data:/data alpine:3.22 sleep 3600
The classic example from the days of cloud block storage plugins reads the same way: a MySQL container whose data directory is an AWS EBS disk that the plugin creates and attaches on demand.
docker run -d --name mysql \
--volume-driver rexray/ebs \
--mount source=ebs-vol,target=/var/lib/mysql \
mysql
When that container is removed, the EBS disk and its data stay in the cloud, ready for a container on another host.
How it works
A plugin runs next to the Docker daemon and listens on a Unix socket, which the daemon finds under
/run/docker/plugins. The daemon sends it small HTTP requests with JSON bodies.
| Request | When Docker sends it | What the plugin does |
|---|---|---|
VolumeDriver.Create | docker volume create | Creates the volume in the storage system, or records it |
VolumeDriver.Mount | A container that uses the volume starts | Attaches and mounts the storage on the host, returns the path |
VolumeDriver.Path | Docker needs the host path | Returns the path |
VolumeDriver.Unmount | A container that uses the volume stops | Unmounts when nobody uses it any more |
VolumeDriver.Remove | docker volume rm | Deletes the volume |
VolumeDriver.Get, List | docker volume inspect, ls | Reports the volumes it knows |
VolumeDriver.Capabilities | On first use | Says whether its volumes are local to a host or global to a cluster |
Parts:
- docker run (--mount ...,volume-driver=X)
- dockerd (Docker daemon)
- Volume plugin X (listens on a Unix socket)
- Storage system (NFS, SSH host, cloud disk)
- Path on the host (returned by the plugin)
- Container (/var/lib/mysql)
Connections:
- docker run to dockerd: asks
- dockerd to Volume plugin X: Mount
- Volume plugin X to Storage system: attaches the storage
- Storage system to Path on the host: mounted
- Path on the host to Container: bind
The important design point: Docker knows nothing about the storage system. It asks for a mounted path and bind-mounts that path into the container. All knowledge about NFS, SSH or a cloud API is inside the plugin, so a vendor can support new storage without any change to Docker.
Under the hood · Why Kubernetes did not simply reuse Docker volume plugins
The Docker interface was designed for one daemon on one host, and three things are missing for a cluster.
- Attach is not separate from mount. A cloud disk must be attached to the right virtual machine before it can
be mounted. In a cluster a central controller should do that, because nodes should not hold cloud credentials.
The Docker API has a single
Mountcall that runs on the host. - No capacity, topology or snapshots. The API cannot say "10 GiB, in the zone of this node".
- It is tied to Docker. Kubernetes supports several container runtimes, and containerd and CRI-O have no Docker plugin system.
Kubernetes first compiled storage code into its own binaries ("in-tree" plugins), then added FlexVolume, an interface that calls executables on each node. Both are replaced by the Container Storage Interface, which splits the work into controller and node operations and is independent of the orchestrator. Docker Swarm itself has supported CSI drivers for cluster volumes since Docker Engine 23.
From Docker to Kubernetes
Parts:
- docker plugin install (per host)
- --driver NAME (docker volume create)
- --opt key=value (docker volume create)
- docker volume create (asks for a volume)
- CSI driver Pods (installed in the cluster)
- provisioner: NAME (in a StorageClass)
- parameters: (in a StorageClass)
- PersistentVolumeClaim (asks for a volume)
Connections:
- docker plugin install to CSI driver Pods: becomes
- --driver NAME to provisioner: NAME: becomes
- --opt key=value to parameters:: becomes
- docker volume create to PersistentVolumeClaim: becomes
| Docker | Kubernetes |
|---|---|
Volume driver local | emptyDir, hostPath and local volumes: storage of the node itself |
local with type=nfs | An nfs volume or an NFS PersistentVolume |
| Third-party volume plugin | A CSI driver |
docker plugin install, per host | CSI driver Pods, deployed once per cluster |
--driver NAME | provisioner: NAME in a StorageClass, or csi.driver in a PersistentVolume |
--opt key=value | parameters: in a StorageClass |
docker volume create | A PersistentVolumeClaim |
Using it
Example · Find out which driver holds a container's data
docker inspect -f '{{range .Mounts}}{{.Type}} {{.Driver}} {{.Name}} -> {{.Destination}}{{"\n"}}{{end}}' db
volume local nfs-db -> /var/lib/mysql
Then ask the volume for its options:
docker volume inspect -f '{{json .Options}}' nfs-db
{"device":":/exports/db","o":"addr=10.0.0.10,rw,nfsvers=4","type":"nfs"}
The driver is local, but the options show that the data is on an NFS server.
Example · A memory-backed volume with the local driver
docker volume create --driver local \
--opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 scratch
docker run --rm -v scratch:/scratch alpine:3.22 df -h /scratch
Filesystem Size Used Available Use% Mounted on
tmpfs 100.0M 0 100.0M 0% /scratch
The same type, device and o options work for any file system the host can mount.
Example · Manage plugins
docker plugin ls # installed plugins and whether they are enabled
docker plugin inspect vieux/sshfs # settings, mounts and the socket of a plugin
docker plugin disable vieux/sshfs # stop it; its volumes cannot be mounted now
docker plugin enable vieux/sshfs
docker plugin rm vieux/sshfs # refuses while volumes of this driver exist
docker volume rm asks the driver to delete the volume. With an external driver that can mean deleting the
remote data, so read the plugin's documentation first.
Tricks
Common mistakes
- Mixing up storage drivers and volume drivers.
overlay2has nothing to do with where volumes are stored, and a volume plugin has nothing to do with image layers. - Assuming a
localvolume follows the container to another host. Only the definition is per host, and without NFS options the data is on that host's disk. - Passing driver options with
-v. They are ignored or rejected. Use--mountwithvolume-opt=or create the volume first. - Forgetting that options are plugin-specific.
sshcmdmeans something tovieux/sshfsand nothing to any other driver. There is no standard list. - Removing a volume to "detach" it.
docker volume rmcan delete the remote data. Removing the container is enough to detach. - Expecting Docker plugins to work in Kubernetes. Kubernetes nodes run containerd, and Kubernetes has its own storage interface, CSI.
Recap
- Every Docker volume belongs to a volume driver. A storage driver is something else: it manages layers.
- The default driver,
local, keeps data under/var/lib/docker/volumes, and with--opt type=,device=ando=it mounts NFS, CIFS, tmpfs or a block device instead. - Third-party plugins put volumes on external storage. Install with
docker plugin install, select with--driverorvolume-driver=, configure with--optorvolume-opt=. - Docker only asks the plugin to mount the volume and bind-mounts the returned path into the container.
- Kubernetes keeps the idea and standardises it: CSI drivers, selected by a StorageClass, asked through claims.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.