Interview Q&A / Docker & Kubernetes

IntermediateQuick answer1 min readUpdated 3 Oct 2026

Your Docker image is 1.5 GB. How would you reduce its size?

SHORT ANSWER

Use a smaller base image, a multi-stage build, a .dockerignore, install only production dependencies, chain and clean package installs in one RUN, and inspect layers with docker history or dive to find the heavy ones.

Explain it simply

Start like a doctor: measure before treating. docker history myapp lists each layer with its size; the tool dive shows what each layer adds.

Then apply the usual fixes in order of payoff. (1) Switch from a full node or ubuntu base to a -slim or distroless one. (2) Use a multi-stage build so compilers and dev dependencies stay in the build stage. (3) Add a .dockerignore so .git, node_modules and test data are not copied. (4) Install production dependencies only, such as npm ci --omit=dev or pip install --no-cache-dir. (5) Remove package caches in the same RUN that creates them. (6) Do not copy large datasets or model files into the image; mount or download them at runtime.

Smaller images pull faster in CI and on new nodes, and contain fewer vulnerabilities.

Example

bash
docker images myapp              # SIZE column
docker history myapp             # size per layer
# Dockerfile tips
# RUN pip install --no-cache-dir -r requirements.txt
# RUN npm ci --omit=dev

What to say in the interview

"I inspect layers with docker history or dive, then switch to a slim base, use multi-stage builds, add a .dockerignore, install only production dependencies, clean caches in the same RUN, and keep big data out of the image."

Common mistakes

  • Optimising randomly without checking which layer is actually large.

#docker#image-size#optimisation

Related questions

Practise more Docker & Kubernetes questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Docker & Kubernetes quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.