Bind mount or named volume for local development of a Node app?
BeginnerScenarioVolumes, storage and data
Answer
Situation read → Developers want live code reload.
What I'd do → Bind mount the source (-v $PWD:/app) and shadow node_modules with a named or anonymous volume (-v /app/node_modules) so host and container binaries do not clash. With Compose use develop.watch (action: sync) for efficient syncing.
Why → Bind mounts reflect host edits instantly; volumes are better for data and performance on macOS/Windows.
Interview tip → Bind mounts in prod couple the container to host paths; avoid them there.
More on Volumes, storage and data
A Postgres container was removed and the data is gone. How should it have been run?BeginnerHow do you back up a named volume?IntermediateTwo containers must share files. What are your options?BeginnerA container needs a writable temp area but the root filesystem is read-only.IntermediateMoving a database volume from one Docker host to another.IntermediateExplain how copy-on-write affects performance of a write-heavy container.Advanced