Base Images (FROM, Official Images, scratch)
Pick official, minimal, or scratch bases and pin digests for reproducible builds.
In plain words
Choose a base for the runtime dependencies you actually need, then pin the identity you want to reproduce.
Think of it like…
Buying a starter kit means tools are included; starting from scratch means you must pack the screws, certificates and instruction sheet yourself.
Where you’ve seen it
In practice, FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server is the concrete move for this job: pick official, minimal, or scratch bases and pin digests for reproducible builds. The release is not accepted until docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison confirms the result.
Words you’ll hear
- FROM
- The implementation control in
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /serverfor pick official, minimal, or scratch bases and pin digests for reproducible builds. - Official
- The result to observe with
docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison, rather than infer from a successful command alone. - scratch
- The production boundary exposed when copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.
Visual diagram
Theory & deep dive
FROM control path
The concrete mechanism is FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server. The observable result is docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison; if those disagree, inspect the runtime evidence before changing unrelated settings.
Pick official, minimal, or scratch bases and pin digests for reproducible builds. Keep FROM, Official and scratch in the same deployment record so the intent and the observed state cannot drift apart.
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server
docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison, not with command success alone.scratch failure boundary
A convenient ubuntu base can carry CVEs and hundreds of megabytes that the app never uses, while scratch succeeds only for statically linked binaries that include every required runtime file. A digest pin can make the source immutable but still needs a deliberate update process. The narrow failure to design for is copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.
Accept this compromise explicitly: Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility. The controlled check-docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison-also identifies the point where a different design is safer.
Exercise this failure safely: copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.
How it works, step by step
Step 1 of 41. State the boundary
Write down why the workload needs this: A convenient ubuntu base can carry CVEs and hundreds of megabytes that the app never uses, while scratch succeeds only for statically linked binaries that include every required runtime file. A digest pin can make the source immutable but still needs a deliberate update process.
- Intent
- FROM
When to use it & trade-offs
What it is
FROM selects the image snapshot that begins a build and can pin a tag, digest or named stage. An official image is a maintained distribution contract; scratch is an empty filesystem with no shell, CA bundle, timezone data or package manager.
Why it matters: A convenient ubuntu base can carry CVEs and hundreds of megabytes that the app never uses, while scratch succeeds only for statically linked binaries that include every required runtime file. A digest pin can make the source immutable but still needs a deliberate update process.
When to reach for it
- The fit is strongest for this job: pick official, minimal, or scratch bases and pin digests for reproducible builds. Pair it with
docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparisonin the runbook. - Production FROM changes should make Official observable through
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server, rather than trusting the runtime default. - Keep a rollback example for the case where copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.
When to avoid or be careful
- Do not accept command success while the system can still fail by copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.
- Avoid erasing scratch protection merely to dodge this cost: “Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility”.
- Do not replace the evidence path-
docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison-with a screenshot or a mutable tag.
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server: practical choices
Strengths: FROM selects the image snapshot that begins a build and can pin a tag, digest or named stage. An official image is a maintained distribution contract; scratch is an empty filesystem with no shell, CA bundle, timezone data or package manager.
Watch out: Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility.
Strengths: It can begin with FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server and fewer surrounding controls.
Watch out: It silently accepts copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest, which makes the result hard to reproduce after promotion.
Strengths: A convenient ubuntu base can carry CVEs and hundreds of megabytes that the app never uses, while scratch succeeds only for statically linked binaries that include every required runtime file. A digest pin can make the source immutable but still needs a deliberate update process.
Watch out: The platform adds an ownership and debugging layer; retain docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison as the direct check.
Interview signals & numbers to know
When this topic comes up
- FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server
- docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison
- Failure signature: copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest
- Trade-off: Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility.
Benchmarks & rules of thumb
- 0 files
- present in the scratch base itself
- 64 hex
- characters in a pinned sha256 digest
- 1 base digest
- resolves the exact upstream rootfs used
Common mistakes & follow-ups
Common interview mistakes
- Treating a successful
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /serveras proof and skippingdocker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison. - Copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest
- Optimizing FROM without accepting that official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility.
Likely interviewer follow-ups
- Why does
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /serveraddress FROM here rather than through application code? - How would you distinguish healthy Official from the failure “copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest” using
docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison? - When would this trade-off-“Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility”-justify a different scratch design?
FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server-and one proof-docker inspect --format {{index .RepoDigests 0}} acme/server:1.0 and run getconf GNU_LIBC_VERSION inside a non-scratch comparison. Then name the boundary: copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.Knowledge check
Put it into practice
Practice related interview Q&A
Apply Base Images (FROM, Official Images, scratch) with generative AI interview Q&A and hands-on practice.