Docker: "I installed the package, why can't the container see it?!"

A frontend-under-Docker classic. The usual config:
volumes:
- ./ui:/app
- /app/node_modulesThe second volume is an anonymous volume: it "protects" node_modules from the source-code mount. Handyβ¦ until the day you add a package. π€
Because that anonymous volume persists across restarts. You rebuild the image with the new package, but the container still mounts the old volume with the old node_modules. The package is nowhere to be found.
The fix I apply systematically after every new dependency:
docker compose rm -fv frontend
docker compose up -d frontendThe -v flag removes the associated anonymous volumes, and the container starts again with the node_modules freshly built into the image.
A small detail β but how many hours have we all lost to this trap? π


