What is a Docker volume?
Why Interviewers Ask This
This is a classic screening question for Docker roles. Hiring managers ask it early in interviews to gauge your baseline understanding and determine if you can communicate technical concepts clearly.
Answer
A Docker volume is a mechanism for persisting data generated by and used by containers. Containers are ephemeral — when a container is removed, its writable layer (and any data written to the container filesystem) is lost. Volumes solve this by storing data outside the container's lifecycle. Three types of data mounting: (1) Named volumes: Docker manages the storage location on the host (docker run -v mydata:/var/lib/mysql mysql). Best for production — Docker handles the path; can be shared between containers; persists after container removal; managed with docker volume ls, docker volume create, docker volume rm; (2) Bind mounts: mount a specific host path into the container (docker run -v /home/user/data:/app/data myapp). Host and container share the directory. Best for development (live code reloading — mount source code); (3) tmpfs mounts: stored in host memory only, never written to disk — for sensitive temporary data. Use volumes for: database files, user uploads, application logs, SSL certificates. Commands: docker volume ls, docker volume inspect myvolume, docker volume prune (remove unused volumes).
Pro Tip
Before answering, structure your response: one-line definition → real-world analogy → concrete example from a project. This makes even complex Docker answers easy to follow.
Previous
What is the difference between CMD and ENTRYPOINT in Dockerfile?
Next
What is Docker Compose?