Interview Prep/Docker/Containers that exit, crash or misbehave

`Error: Cannot find module` in container but works on the host.

IntermediateTroubleshootingContainers that exit, crash or misbehave
Answer

Likely causes → node_modules excluded by .dockerignore but npm install not run, a bind mount shadowing /app/node_modules, or platform-specific native modules built on the host.

Diagnose →

docker run --rm image ls /app/node_modules | head
docker inspect -f '{{json .Mounts}}' c

Fix → Install dependencies in the image, mask node_modules with a named volume when bind mounting, never copy host node_modules.

Prevent → .dockerignore with node_modules and npm ci in the Dockerfile.

All Docker questions Roadmap: Docker & containers

More on Containers that exit, crash or misbehave