How do you persist data in Docker? Explain volumes versus bind mounts.
What they are really testing: Whether you know the container filesystem is ephemeral and can distinguish named volumes (Docker-managed) from bind mounts (host path), and when to use each.
A real interview question
How do you persist data in Docker? Explain volumes versus bind mounts.
What most people say
drag me
“You use a volume to save data so it is not lost when the container stops.”
It knows volumes exist but does not distinguish named volumes from bind mounts or say when to use each, which is the actual question and matters for portability vs dev convenience.
The follow-ups they ask next
Why prefer a named volume over a bind mount for a database in production?
Named volumes are Docker-managed and portable, not tied to a host path/layout, with better lifecycle and backup handling. Bind mounts couple you to the specific host directory, which is fragile across machines.
When is a bind mount the better choice?
Local development: mounting your source directory so code edits on the host are reflected live in the container without rebuilding, enabling fast iteration and hot reload.
What the interviewer is listening for
- Knows container FS is ephemeral
- Distinguishes named volume vs bind mount
- Maps each to the right use case
What sinks the answer
- Only "use a volume"
- Cannot distinguish volume from bind mount
- Would bind-mount production data
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“The container FS is [ephemeral, lost on removal], so persistent data needs external storage. A [named volume is Docker-managed, portable, the choice for production data like a DB]. A [bind mount maps a host directory in, great for dev live-editing but tied to the host path]. Plus [tmpfs in memory]. Rule: [named volumes for app data, bind mounts for dev].”
Keep going with docker
Foundation
What is a container, and how is it different from a virtual machine?
Foundation
What is the difference between a Docker image and a container?
Foundation
What is a Dockerfile, and what do the main instructions do?
Junior
How does the Docker build cache work, and how do you order a Dockerfile to use it well?
Junior
What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?
Junior
How does container networking work in Docker, and how do containers talk to each other?
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free