What is a Volume
A volume is a persistent storage directory managed by the container runtime. It exists outside the container's overlayfs layers, so data in a volume survives when the container is stopped, restarted, or removed. Without a volume, all data written inside a container is lost when the container is deleted.
How it works
Docker stores volumes at /var/lib/docker/volumes/ on the host. When you create a volume (docker volume create pgdata) or declare one in docker run -v pgdata:/var/lib/postgresql/data, Docker creates a directory on the host and bind-mounts it into the container's filesystem.
Volumes bypass the union filesystem entirely. Reads and writes go directly to the host filesystem, which means volumes have native I/O performance — no copy-on-write overhead.
Named volumes persist until explicitly deleted with docker volume rm. Anonymous volumes (created without a name) are removed when the container is removed with --rm or docker rm -v.
Volume drivers extend storage beyond the local filesystem. Cloud volume drivers mount network storage (AWS EBS, NFS, GlusterFS) as container volumes, enabling data to persist across hosts.
Why it matters
Containers are ephemeral — their writable layer is temporary by design. Any data that must survive container lifecycle events (database files, upload directories, configuration state) must use a volume. Kubernetes PersistentVolumes and PersistentVolumeClaims are the same concept at orchestration scale.
See How Containers Work for how the writable layer and volumes interact.