Card 03/ 05

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.

Two ways to keep what a container writes
Compared onBind mountNamed volume
Written as-v /path/on/host:/path/in/container-v mydata:/path/in/container
Where the files areA directory you chose, on this machineA directory Docker manages and you do not name
Who owns the pathYou. It exists whether Docker runs or notDocker. It exists because you asked for a volume
Moves to another machineOnly if that machine has the same pathBy name, with no path to agree on
What it is forFiles you edit on the host and want the container to seeData 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.