Interview Prep/Docker/Image design and Dockerfile decisions

A teammate's Node.js image is 1.2 GB. How do you approach shrinking it?

BeginnerScenarioImage design and Dockerfile decisions
Answer

Situation read → Large image usually means a fat base, dev dependencies, build tools and a copied build context.

What I'd do →

  1. Run docker history --no-trunc myapp:latest and docker image ls to see which layers are big.
  2. Switch from node:22 to node:22-slim or node:22-alpine (test musl compatibility first).
  3. Use npm ci --omit=dev and add a .dockerignore with node_modules, .git, *.md.
  4. Move to multi-stage so build tooling never ships.

Why → Every layer is additive; deleting files in a later layer does not shrink the image.

Interview tip → Say you measure with docker history or dive before optimizing.

All Docker questions Roadmap: Docker & containers

More on Image design and Dockerfile decisions