JuniorContainers

Our Docker image is 1.2 GB and takes 8 minutes to build. How would you make it smaller and faster?

What they are really testing: Whether you understand layer caching and multi-stage builds, the two things that fix 90% of slow bloated images. They want you to reason about cache invalidation order, not just recite "use alpine".

A real interview question

Our Docker image is 1.2 GB and takes 8 minutes to build. How would you make it smaller and faster?

What most people say

drag me

Switch the base image to alpine.

It is one real lever pulled in isolation, and often the least effective one. It does nothing about build time, and alpine brings its own problems with musl libc that can cost more debugging time than the megabytes saved.

The follow-ups they ask next

  • Why not always use alpine?

    It uses musl instead of glibc, which can break native modules and produce subtle runtime differences or slower DNS. Distroless or a slim variant is often a safer size win.

  • The build is fast locally but slow in CI. Why?

    CI usually starts with a cold cache. You need a shared layer cache, registry-backed caching, or a build tool that persists cache between runs.

What the interviewer is listening for

  • Explains cache invalidation order
  • Reaches for multi-stage builds
  • Measures rather than guessing

What sinks the answer

  • Only names a base image swap
  • Does not know instruction order affects caching
  • Ships build tooling in the final image

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.

Build time is usually [cache invalidation from copying source before installing dependencies], so [copy the lock file, install, then copy source]. Size is usually [shipping build tooling], so [multi-stage build copying only runtime output], plus [a dockerignore and a slimmer base].

Keep going with containers

All 87 devops engineer questions

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