Java Zero to All All questionsPractise free
Interview questions › DevOps: Docker, Kubernetes & Helm › Docker & Containers

When should you use a named volume vs a bind mount, and why are containers themselves a bad place to keep data?

Level II · JuniorDocker & Containers
Short answer

A container's writable layer is ephemeral — removing the container destroys it — so any data that must survive (databases, uploads) goes on a volume.

Explanation

Named volumes are managed by Docker and are the portable production choice for stateful services; bind mounts map a specific host path and are great for live-reloading source in dev but couple you to host layout and permissions, making them poor for production. The general principle is to keep containers stateless and immutable and push all durable state to volumes or external services.

Common mistakes
  • Writing data to the container filesystem.
  • Using bind mounts in production without thinking about permissions.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Docker & Containers.

Practise free

More on Docker & Containers