Skip to main content

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

Docker
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_modules

The 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 frontend

The -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? πŸ˜„

See the original post on LinkedIn