What is the difference between a named volume and a bind mount?
A named volume is storage created and managed by Docker, stored in its own area and portable between containers. A bind mount maps an exact host folder into the container, which suits live code editing but depends on the host layout.
Explain it simply
A named volume is a locker in the college's storage room: the staff handle where it is, you just remember the locker name. A bind mount is carrying your own bag and placing it on the desk: you know exactly where it sits on your side.
With -v pgdata:/var/lib/postgresql/data, Docker creates and manages pgdata; it survives container removal, works on any OS, and is the right choice for databases. With -v "$(pwd)":/app, your project folder appears inside the container, so editing code on your laptop instantly changes what the container sees. That is great for development with hot reload. Downsides of bind mounts: they depend on the host path existing, can have permission and performance issues on Docker Desktop, and give the container direct access to host files.
Example
docker run -d -v pgdata:/var/lib/postgresql/data postgres:16 # named volume
docker run -d -v "$(pwd)":/app -w /app node:20 npm start # bind mount
docker volume lsWhat to say in the interview
"Named volumes are Docker-managed, portable and best for persistent data like databases. Bind mounts map a specific host path, best for development with live code reload but tied to the host layout."
Common mistakes
- Bind-mounting node_modules from a different OS into the container.