Why does a container need extra storage for persistent data, and what are the three storage options Docker offers?
A container's own filesystem disappears when the container is removed; volumes (Docker-managed), bind mounts (any host folder) and tmpfs mounts (RAM, never persistent) keep data outside it.
By default everything a container writes goes into its writable layer, which is deleted together with the container. A database whose container crashes and is recreated would start empty. Data that must survive therefore lives outside the container:
| Type | Where the data lives | Persistent? | Key property |
|---|---|---|---|
| Volume | /var/lib/docker/volumes/<name>/_data, managed by Docker |
Yes | Only Docker processes (and users in root/docker) can get at it; can be listed, inspected, shared, backed up |
| Bind mount | Any existing host path, such as ~/dockerlab |
Yes | Not managed by Docker; host and container see the same files live, both can change them |
| tmpfs mount | Host memory (RAM) | No: gone when the container stops | Very fast; nothing touches the disk, which also suits sensitive data such as secrets |
Rule of thumb: volumes for application data in production (databases), bind mounts for development (edit code on the host, run it in the container) or to inject a config file, tmpfs for scratch data or secrets that must not hit the disk.
* Bind mount and volume on disk, tmpfs in RAM. *
Go deeper:
TechWorld with Nana: Docker Volumes explained in 6 minutes — why containers need volumes and the volume types.
Docker Docs: Storage — volumes, bind mounts and tmpfs compared.
Wikipedia: tmpfs — the RAM-backed filesystem behind tmpfs mounts.