🐳 Docker Intermediate

What is Docker BuildKit and why is it better?

Why Interviewers Ask This

This question targets practical, hands-on experience with Docker. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

BuildKit is the next-generation build backend for Docker, enabled by default in Docker Desktop and Docker Engine 23.0+. It provides significant improvements over the legacy builder: (1) Parallel building: BuildKit analyzes stage dependencies and builds independent stages in parallel; (2) Better cache: cache is more granular and can be exported/imported across machines (inline cache in registry, external cache with --cache-from/--cache-to); (3) Secrets at build time: RUN --mount=type=secret,id=npmrc cat /run/secrets/npmrc — pass secrets without baking them into image layers; (4) SSH forwarding: RUN --mount=type=ssh git clone git@github.com:private/repo — use SSH keys without embedding them; (5) Bind mounts in RUN: RUN --mount=type=bind,source=.,target=/src; (6) Cache mounts: RUN --mount=type=cache,target=/root/.npm npm install — persistent cache between builds (huge for npm, pip, apt); (7) Faster and more informative output; (8) Multi-platform builds with docker buildx. Enable in older versions: DOCKER_BUILDKIT=1 docker build .. Use docker buildx build for full BuildKit features. BuildKit is the foundation for multi-architecture image building.

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.