DockerCoreOpsPostmanFreshworksAsked in DevOps engineer and Platform engineer roundsRead the full interview experience →PASS
Your Node.js image is 1.2 GB. How do you get it under 200 MB?
The scenario
CI pushes are slow and node scale-ups take minutes because every new node pulls a 1.2 GB image.
Model answer
- Multi-stage build: install dependencies and build in a full image, then copy only the build output and production node_modules into a slim runtime image.
- Use a small base: node:<version>-slim or a distroless image, not the full Debian image.
- npm ci --omit=dev in the runtime stage, and clear the npm cache in the same RUN layer.
- A .dockerignore for node_modules, .git, tests and local env files.
- Order layers for caching: copy package*.json and install before copying the source.
- Check with docker history or dive to see which layer is big.
Common mistakes
- rm -rf in a separate RUN, which doesn't remove the earlier layer
- No .dockerignore
- Copying the whole source before installing dependencies