DevOps Engineer Interview Question

How do you keep container images small and secure?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

Use multi stage builds so compilers and build dependencies never reach the final image, start from a minimal base such as distroless or slim, and run as a non root user. Order layers so dependency installation caches separately from source, add a .dockerignore, pin base images by digest, and scan on build. Never pass secrets as build arguments, because they persist in the layer history.

Why interviewers ask this

The interviewer wants to know whether you treat images as build artifacts with a supply chain or as a place to dump a filesystem. They look for multi stage builds and layer caching as the size answers, and non root, minimal base and pinned digests as the security answers. Mentioning that build arguments leak into history shows practical experience rather than a memorized checklist.

How to structure your answer

  • Split the answer into size and security so it stays organized.
  • Name multi stage builds and layer ordering for size.
  • Cover base image choice, non root, and pinning for security.
  • Add scanning, SBOM generation, and the secrets in layers trap.

Example answer

Spoken example, first person

For size, the two things that do the heavy lifting are multi stage builds and layer ordering. Build in a full image with the toolchain, then copy just the compiled output into a minimal runtime, which typically takes an image from several hundred megabytes to tens. Ordering matters because the dependency install should be its own layer above the source copy, otherwise every code change invalidates the cache and rebuilds everything. A .dockerignore stops the local git directory and node modules being sent to the daemon at all. For security, I run as a non root user with a read only root filesystem where the app allows it, pin the base image by digest so a rebuild is reproducible, and rebuild regularly so base patches land rather than pinning and forgetting. Scanning runs in the pipeline and fails on fixable high severity findings, and we publish an SBOM with the image so we can answer the which services use this library question in minutes when the next big advisory lands. Secrets never go in build args; they are visible in the history.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How do you get a secret into a build without it landing in a layer?
  • How do you handle a scanner finding with no available fix?
  • What breaks when you move to a distroless base, and how do you debug it?

Related devops engineer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot