Interview prep

Docker Interview Questions

Docker questions focus on image layering, build efficiency and the container/VM boundary.

Questions and answers

01How do containers differ from virtual machines?

Containers share the host kernel and isolate with namespaces and cgroups; VMs virtualise hardware and run their own kernel. Containers start faster and pack denser, VMs isolate more strongly.

02What is a multi-stage build and why use it?

It builds artefacts in a heavy toolchain stage and copies only the output into a slim runtime stage, cutting image size and attack surface dramatically.

03How does Docker layer caching work?

Each instruction produces a layer keyed by its inputs. Ordering matters: copy dependency manifests and install dependencies before copying source, so code edits don't invalidate the dependency layer.

04COPY vs ADD?

Use COPY. ADD additionally auto-extracts archives and fetches URLs, which is surprising behaviour you rarely want.

05How do you keep container images secure?

Pin minimal base images, run as a non-root user, scan for CVEs in CI, avoid baking secrets, and rebuild regularly to pick up base-image patches.

How to answer these well

Interviewers are not grading recall — they are checking whether you've hit the failure mode the question describes. Anchor every answer to something you actually shipped or debugged with Docker.

Say the trade-off out loud. "I'd use X here, but it costs Y under Z conditions" scores higher than a clean textbook definition every time.

Roles asking for Docker

Related prep