Card 03/ 05
All 5 cards
ComparisonDifficulty: Intermediate1 min
A Bind Mount Beside a Named Volume
Both put something into the container that outlives it. They differ in who owns the files, which decides which one you want.
| Compared on | Bind mount | Named volume |
|---|---|---|
| Written as | -v /path/on/host:/path/in/container | -v mydata:/path/in/container |
| Where the files are | A directory you chose, on this machine | A directory Docker manages and you do not name |
| Who owns the path | You. It exists whether Docker runs or not | Docker. It exists because you asked for a volume |
| Moves to another machine | Only if that machine has the same path | By name, with no path to agree on |
| What it is for | Files you edit on the host and want the container to see | Data the container produces and must keep |
Use a bind mount when the host is the source of truth — your source code during development, a config file you maintain. Use a named volume when the container is the source of truth, which is almost always what a database wants.