Data categories
- Non-persistent
- Ephemeral data.
- Every container has it (the writable top layer of the image filesystem).
- Tied to the container lifecycle.
- Persistent
- Volumes.
- Decoupled from individual containers.
Local (non-persistent) storage
- All containers use local storage by default.
- Storage locations:
- Linux:
/var/lib/docker/<STORAGE-DRIVER>/ - Windows:
c:\ProgramData\Docker\windowsfilter\
- Linux:
- Common drivers by distro:
- RHEL:
overlay2 - Ubuntu:
overlay2oraufs - SUSE:
btrfs - Windows: its own driver
- RHEL:
See Storage drivers for UnionFS driver details.
Bind mounts
Bind mounts have existed since early Docker releases. They are more limited than volumes.
A bind mount mounts a file or directory from the host into the container.
When to use bind mounts
Use them when you need to mount configuration files into a container.
Volumes
Volumes use a directory under Docker’s storage path on the host. Docker manages that directory.
- Use a volume for persistent data:
- Create the volume.
- Create your container.
- Mounted to a path inside the container.
- Data is written to the volume.
- Deleting a container does not delete the volume.
- First-class objects with their own API and subcommands.
- Default local driver creates storage on the Docker host.
- Third-party drivers:
- Block storage (high performance): Amazon EBS, OpenStack Cinder.
- File storage: NetApp FAS, Azure File Storage, Amazon EFS.
- Object storage (large, rarely changed files): Amazon S3, Ceph, MinIO, OpenStack Swift.
- Storage locations:
- Linux:
/var/lib/docker/volumes/ - Windows:
c:\ProgramData\Docker\volumes
- Linux:
Related topics
- Working with volumes — declare, mount, and share volumes
- Storage drivers — AUFS, Overlay, devicemapper, BTRFS, ZFS
- Images overview — image layers and UnionFS
Andrew Dorokhov