Card 04/ 05
All 5 cards
GotchaDifficulty: Intermediate1 min
Why Mounting Over a Directory Hides What Was There
The image installed your dependencies at build time. You mount your source directory over the app folder to get live edits, and the container starts up insisting nothing is installed.
$ docker run -v $(pwd):/app my-api
Error: Cannot find module 'express'Nothing was deleted. A mount replaces what is at that path for as long as the container runs: the container now sees your host directory there, and your host directory has no node_modules in it because the install happened inside the image.
| Without the mount | With the mount |
|---|---|
The image's /app, dependencies included | Your host directory, exactly as it is |
The usual fix is a second mount that puts a volume over the directory you want the image's version of, so the host directory covers the source and nothing covers the dependencies.