Docker interview question · Most asked

Volumes, bind mounts and tmpfs: when do you use each?

Summary

Named volumes are managed by Docker and are the right choice for persistent container data (databases in development, uploaded files); bind mounts map a host path into the container, ideal for development (live-editing source code) or specific host files; tmpfs mounts keep data in memory only, for temporary or sensitive data.

Longer Answer

Data in a container's writable layer disappears with the container and is slower (copy-on-write), so anything that must persist goes in a volume. Bind mounts depend on the host's directory layout and permissions (UID mismatches between host and container are a common annoyance) and can expose host files, so avoid them in production. In orchestrators, persistent storage is provided by the platform (Kubernetes PersistentVolumes, EFS for ECS).

Key Points

  • Volumes: persistent, Docker-managed.
  • Bind mounts: dev and host files.
  • tmpfs: memory only.
  • Writable layer is ephemeral.

More most-asked Docker questions

← All Docker questions