Docker Volumes
Containers are ephemeral.
This means:
when containers are deleted, internal data disappears.
Volumes solve this problem.
Why Volumes Matter
Without volumes:
Container Deleted
↓
Data Lost
With volumes:
Container Deleted
↓
Data Survives
Volume Example
docker run -v mydata:/data nginx
Breakdown:
| Part | Meaning |
|---|---|
-v |
mount volume |
mydata |
volume name |
/data |
container path |
Bind Mount Example
docker run -v /host/files:/container/files nginx
This maps:
Host Directory
↔
Container Directory
Very common for:
- configs
- media files
- backups
- development work
Listing Volumes
docker volume ls
Inspect volume:
docker volume inspect mydata