Volume: storage that Docker creates and manages. Docker keeps it in its own area on the host, and you refer to it by name. Example: -v pgdata:/var/lib/postgresql/data.
- It lives longer than any container.
- It works the same on any host.
- It is the recommended way to keep data, such as a database.
Bind mount: it maps a specific host folder into the container. Example: -v $(pwd):/app.
- The container sees the host files directly.
- This is ideal in development, for live-reloading source code.
- But it depends on the host's folder layout and permissions.
tmpfs mount: it lives only in the host's memory. It disappears when the container stops. Use it for temporary or sensitive files that you don't want written to disk.
- A volume is managed by Docker, has a name and is best for data you must keep.
- A bind mount maps a host folder and is great for source code in development.
- A tmpfs mount lives in memory and is gone when the container stops.
- Volumes work on any host, but bind mounts depend on the host.
Read more