Keep data alive beyond a container: named volumes for app data managed by Docker, bind mounts for host folders like source code, tmpfs for throwaway in-memory files.
| Type | Syntax | Best for |
|---|---|---|
| Named volume | -v pgdata:/var/lib/postgresql/data | Databases, app data: managed, portable, fast |
| Bind mount | -v $(pwd):/app or -v /host/path:/path | Live-reloading source code, config files |
| tmpfs | --tmpfs /tmp | Scratch files kept in RAM, never on disk |
Add :ro to mount read-only: -v ./nginx.conf:/etc/nginx/nginx.conf:ro
/app hides node_modules built in the image)-v with a host path that does not exist silently creates an empty folder owned by root; --mount fails instead