Dockerfile & Images
The build recipe: the instruction set from FROM through ENTRYPOINT, multi-stage builds, the build context, and the BuildKit engine that runs them. A Dockerfile is short enough to read in an interview and instantly shows how you think about size and root.
part ofDockeroverview, primer and where to startread it →on this pageshowhide
explore
- Base Images & FROM4 questions
- RUN, COPY & ADD4 questions
- CMD vs ENTRYPOINT5 questions
- ARG vs ENV5 questions
- USER, WORKDIR & Metadata Instructions6 questions
- Multi-Stage Builds5 questions
- Build Context & .dockerignore5 questions
- BuildKit, Secrets & Cache Mounts5 questions
- BuildKit vs Legacy Builder4 questions
- Multi-Platform Builds4 questions
- Dockerskillanchors this topic
- AI Engineerrole
- Backend Developerrole
- Data Engineerrole
- DevOps / SRE Engineerrole
- DevSecOps Engineerrole
- Forward Deployed Engineerrole
- Full Stack Developerrole
- GitLab CI/CDskill
- Java Backend Developerrole
- Java SDETrole
- Kotlin Backend Developerrole
- MLOps Engineerrole
- Machine Learning Engineerrole
- PostgreSQL DBArole
- QA Engineerrole
- Server-Side Game Developerrole
questions
page 2 of 2A Python service builds and runs fine on a Debian-based image, but after someone switches the Dockerfile's FROM instruction to an Alpine base the build gets much slower and a native library fails to load at runtime. Explain what is going on and how you would decide whether to stay on Alpine.
basics
~20 sAlpine uses musl libc instead of glibc, so precompiled binaries and Python manylinux wheels built for glibc do not apply. Package managers fall back to compiling from source, which is slow and needs toolchains, and mismatched native libraries fail to load. Unless you have verified the native dependency chain, prefer a glibc -slim base.
A `docker buildx build` on a docker-container builder succeeds, yet `docker images` lists nothing new. Why, and how do you get the image out?
basics
~20 sThe docker-container buildx driver runs BuildKit outside the engine's image store and exports nothing by default, so the result stays in the builder. Add --load to import it into the local engine, or --push to publish it.
You must publish one container image tag that runs on both linux/amd64 and linux/arm64. How do you build and publish it with docker buildx, and what are the trade-offs between emulation and native or cross-compiled builds?
basics
~20 sUse docker buildx build --platform linux/amd64,linux/arm64 --push, which produces one manifest list (image index) referencing a per-architecture image. The foreign architecture can run under QEMU emulation (simple but slow), on native builder nodes (fast, needs machines of both architectures), or via cross-compilation using BUILDPLATFORM and TARGETARCH (fastest, needs a cross-compiling toolchain).
Describe the entrypoint wrapper-script pattern used by images such as the official Postgres image: what work belongs in that script, how it is wired up in the Dockerfile, and why the script must end with `exec "$@"`?
basics
~20 sSet ENTRYPOINT to a small script and CMD to the real command. The script does start-up work — render config, fix permissions, first-run initialisation — then runs exec "$@", replacing itself with the CMD so the real process becomes PID 1 and receives signals.
A team reports that `docker build` pauses for over a minute before the first instruction runs, and that any one-line source change rebuilds nearly everything. How would you diagnose and fix this?
basics
~20 sThat pause is the build context being walked and transferred. Measure it with --progress=plain, find the bulk with du, and exclude version-control, dependency and build-output directories via .dockerignore at the context root — which also stops unrelated files from invalidating the COPY layer's cache.
A Docker container exits immediately with `exec format error` on an arm64 host but runs on amd64. How do you diagnose and fix it?
basics
~20 sThe kernel could not execute the binary because it was compiled for another architecture and no emulation handler is registered. Check the image's recorded architecture, rebuild the image for the host's platform, or run it with docker run --platform and accept the emulation cost.
How does splitting a Dockerfile into several build stages change build parallelism and layer-cache invalidation compared with one long linear Dockerfile, and how should you order instructions inside each stage to benefit?
basics
~20 sStages form a dependency graph, not a list. Independent stages build concurrently, unreferenced stages are skipped, and a cache miss invalidates only the rest of that stage's chain — not sibling stages. Inside each stage, put rarely-changing steps first.
What does the STOPSIGNAL instruction in a Dockerfile control, and when would you set it to something other than SIGTERM?
basics
~20 sSTOPSIGNAL sets which signal the runtime sends to the container's main process on a stop request; the default is SIGTERM, and SIGKILL follows after the grace period. Change it when the application's graceful shutdown uses a different signal, as nginx does with SIGQUIT.
How do you decide which buildx driver and exporter every team's image builds should use, from laptops to CI?
basics
~20 sDecide by where the result must land and how insulated the build must be from the host: the built-in docker driver for laptop iteration, and a docker-container or remote builder in CI with push as the default exporter.
What does the `# syntax=docker/dockerfile:1` line at the top of a Dockerfile do?
basics
~20 sIt is a BuildKit parser directive naming the frontend image that parses the Dockerfile. BuildKit pulls docker/dockerfile:1 and uses it instead of its built-in parser, so newer Dockerfile syntax works without upgrading the Docker Engine.
How do you make the image referenced by a Dockerfile's FROM instruction configurable at build time, and what is the scoping rule for an ARG declared before the first FROM?
basics
~20 sDeclare ARG above the first FROM and use it in the FROM line, for example ARG BASE=debian:bookworm-slim then FROM ${BASE}. Such an ARG lives in a global scope usable only by FROM lines; to use its value inside a build stage you must re-declare a bare ARG with the same name after that stage's FROM.
What do the `--chown` and `--link` flags on a Dockerfile COPY instruction do, and what problem does each one solve that a plain COPY followed by a RUN chown does not?
basics
~20 s--chown sets ownership as the files are written, avoiding a second full-size layer that a later RUN chown would create. --link writes the copied content as a self-contained layer that does not depend on earlier layers, so it stays cached and reusable when the base changes.
Your CI runs Docker builds on ephemeral runners, so every job starts with an empty builder and rebuilds everything. How would you design the build cache strategy, and what are the trade-offs of the options BuildKit gives you?
basics
~20 sExport the build cache to somewhere shared. BuildKit supports --cache-to/--cache-from with an inline cache (embedded in the pushed image, final stage only), a registry cache (separate tag, mode=max keeps intermediate stages), or a local or cloud backend. Weigh cache hit rate against push/pull cost and storage, and scope caches per branch and per platform.
You own the shared base images for dozens of services. How would you standardise the ENTRYPOINT/CMD contract, PID 1 behaviour, and shutdown-signal handling across all of them, and what trade-offs would you weigh?
basics
~20 sMandate exec-form instructions, decide one convention for whether ENTRYPOINT is the app or a thin wrapper, guarantee the real process ends up as PID 1 with a SIGTERM handler, standardise grace periods against measured drain time, and enforce it with lint plus an automated termination test.
In a monorepo with a dozen deployable services that share internal libraries, how would you structure build contexts and ignore files so each service image builds from the smallest correct input, and what trade-offs would you weigh?
basics
~20 sPick one of three shapes: per-service contexts (fast, but shared code must be published), one root context with per-Dockerfile ignore files (simple, pays the walk), or a small context plus BuildKit named contexts for shared libraries. Optimise for cache hit rate and transfer cost, and enforce the ignore files automatically.
Your Docker images must now run on both arm64 and amd64 hosts. How do you decide which ones ship both, and keep the two from diverging?
basics
~20 sDecide per image from where it actually runs, not by default: dual-architecture for shared base images and anything developers run locally, single-architecture where a workload is pinned to one host pool. Then test each architecture on native hardware, because build success is not behavioural parity.
For a fleet of services built in CI, when is a single multi-stage Dockerfile per service the right structure, versus a shared prebuilt builder image, versus having an external build system hand the Dockerfile a finished artifact? What tradeoffs drive that call?
basics
~20 sSelf-contained multi-stage Dockerfiles maximise reproducibility and local parity but rebuild toolchains everywhere. A shared prebuilt builder image centralises the toolchain and speeds cold builds at the cost of a versioned dependency. Copying in an externally built artifact is fastest but loses hermeticity.
showing 31–47 of 47