Docker Volumes vs Bind Mounts
Two ways to persist and share data
By default, anything written inside a container disappears when the container is removed. To persist data, Docker provides two main options: volumes and bind mounts.
- Volumes are managed by Docker. They live under
/var/lib/docker/volumesand can be shared between containers. Best for production, since Docker handles their lifecycle and permissions. - Bind mounts map a host folder directly into a container. Perfect for development, where you want to edit files on your machine and see changes inside the container instantly.
Rule of thumb:
- Use bind mounts for local dev work.
- Use volumes when you need durable, portable storage in production.
Key Terms
Volume
A Docker-managed data store that exists independently of any container. Stored under /var/lib/docker/volumes by default.
Anonymous Volume
A volume created automatically without a name. Tied to the container that created it.
Bind Mount
A mapping of a host directory into a container. Unlike volumes, bind mounts are not managed by Docker.
Persistence
Data that remains available even after containers are stopped or removed.