Your Docker image is 1.5GB. How do you make it smaller?
What they are really testing: Whether you have a concrete toolkit (base image, multi-stage, layer hygiene, .dockerignore) rather than one trick. Image bloat is a daily, practical concern.
A real interview question
Your Docker image is 1.5GB. How do you make it smaller?
What most people say
drag me
“I would use a smaller base image like alpine.”
A smaller base helps but is one lever. A 1.5GB image usually also carries build tools (needs multi-stage), uncleaned caches in layers, and copied junk (needs .dockerignore). One trick rarely gets you there.
The follow-ups they ask next
Why does running rm in a later RUN not shrink the image?
Layers are additive and immutable: the file still exists in the earlier layer. You must create and clean up in the same RUN (or use multi-stage) so the bytes are never committed to a layer.
How do you find which layer is making the image big?
docker history shows per-layer sizes; the dive tool shows layer contents and wasted space, so you can see exactly which instruction added the bulk and target it.
What the interviewer is listening for
- Multiple levers: base, multi-stage, layer cleanup, .dockerignore
- Knows cleanup must be in the same layer
- Inspects layers (history/dive)
What sinks the answer
- Only "use alpine"
- Cleans up in a separate later layer
- No multi-stage or .dockerignore
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“Several levers: [a smaller base (slim/alpine/distroless)], [multi-stage so build tools do not ship], [combine RUN steps and clean caches in the same layer, since deleting later does not shrink earlier], and [a .dockerignore plus prod-only deps]. I [inspect layers with docker history or dive] to target the fattest one.”
Keep going with docker
Foundation
What is a container, and how is it different from a virtual machine?
Foundation
What is the difference between a Docker image and a container?
Foundation
What is a Dockerfile, and what do the main instructions do?
Junior
How does the Docker build cache work, and how do you order a Dockerfile to use it well?
Junior
What is the difference between CMD and ENTRYPOINT, and what is the exec versus shell form?
Junior
How does container networking work in Docker, and how do containers talk to each other?
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free