Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 23/ 160
02. Dockerfiles & Image Building

Base Images (FROM, Official Images, scratch)

Pick official, minimal, or scratch bases and pin digests for reproducible builds.

BeginnerFROM · Official3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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 /server for 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

Loading interactive 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.

Concrete FROM setup

FROM golang:1.24-bookworm AS build; FROM scratch; COPY --from=build /out/server /server

Key takeaway: Prove Official with 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.

Deliberate failure test

Exercise this failure safely: copying a dynamically linked glibc binary into scratch, or running an image from latest without recording its resolved digest.

Key takeaway: Official images accelerate support and debugging; scratch minimizes size and attack surface at the cost of every runtime assumption becoming your responsibility.

How it works, step by step

Step 1 of 4
Design

1. 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.

Choose a base for the runtime dependencies you actually need, then pin the identity you want to reproduce.
Key numbers at this step
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 comparison in 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

Explicit FROM
Best for: Pick official, minimal, or scratch bases and pin digests for reproducible builds, with a reviewed runbook.

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.

Ambient default
Best for: Short-lived Official experiments with low blast radius.

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.

Managed scratch
Best for: Teams that centralize scratch policy across many workloads.

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 /server as proof and skipping docker 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 /server address 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?
Interview tip: Give one concrete operation-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

Loading quiz

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.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
Anatomy of a Dockerfile & Build Context
Next topic
Executing Build Commands (RUN - Shell vs Exec Form)