Sub topic 13
A decision checklist for choosing a base image
This chapter assumes you can build and run images, read a Dockerfile, and use basic Linux commands. It also assumes you know what a package manager and a shared library are. Earlier chapters covered each base image family. Here you combine them into one repeatable decision.
Start with the constraints, not the image
A base image is a trade-off between compatibility, size, attack surface, and debuggability. No family wins on all four. Answer the questions below in order. The first question that rules out an option removes it from the list.
- Does your app need glibc? Prebuilt Python wheels, many Node native add-ons, and vendor binaries assume glibc. Alpine uses musl, so these can fail to install or crash at run time. If you rely on them, start with Debian slim, distroless (Debian based), or a glibc-based hardened image.
- Can you compile to a self-contained artifact? A static Go binary, or a Java or .NET application with its runtime supplied by the image, can be copied into a minimal image. If your app needs a package manager at run time, distroless is a poor fit.
- Do you need a shell or package manager in production? Entrypoint scripts,
apk addat start-up, anddocker exechabits all need a shell. Distroless has none. Remove the dependency or choose Debian slim or Alpine. - How strict is your security policy? If you must show a short list of vulnerabilities, an SBOM, and signed provenance, prefer distroless or Docker Hardened Images. Both ship far fewer packages to scan.
- Who patches the base? With Debian slim and Alpine you rebuild and redeploy when fixes appear. A hardened image catalog adds a maintainer who publishes updates, but you still must rebuild.
Compare the options
| Option | libc | Shell and package manager | Typical use | Main risk |
|---|---|---|---|---|
| Debian slim | glibc | Yes (`apt`) | Python, Ruby, general services | Larger than the others |
| Alpine | musl | Yes (`apk`) | Small tools, Node services without native glibc dependencies | Compatibility surprises |
| Distroless | glibc (Debian based) | No | Compiled apps, multi-stage builds | Harder debugging |
| Docker Hardened Images | Varies by image | Varies by image | Regulated or security-sensitive workloads | Catalog and licensing fit |
A decision flow
Verify with measurements
Do not trust reputation alone. Build your app on two candidate bases and compare them.
docker image ls
docker scout cves myapp:latest
trivy image myapp:latestCompare image size, the count of known vulnerabilities, and whether the container starts and passes your tests. A smaller image that fails under load because of a DNS or locale difference is not a win.
Pin and plan for updates
Once you choose, pin the base by tag and digest so builds are reproducible, and rebuild on a schedule so you pick up security fixes.
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /out/app .
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
ENTRYPOINT ["/app"]For debugging, use the :debug tag in a development build only. It adds a busybox shell, and it should never reach production.
Common mistakes
- Choosing Alpine for size, then adding a compiler and glibc workarounds that remove the benefit.
- Moving to distroless without a debugging plan.
- Pinning a digest once and never rebuilding, so known fixes never arrive.
- Shipping a
:debugimage to production.
Exercise
Your team ships a Python service that depends on a prebuilt wheel for a numerical library, and security requires a short vulnerability report. Which base image do you try first, and what do you check afterward?
Show answer
Start with Debian slim, because the prebuilt wheel targets glibc and Alpine's musl may break it. Then scan with Docker Scout or Trivy and compare the result with a hardened glibc-based image. Run the test suite on the final image, pin the base by digest, and set a rebuild schedule.
Exercise
A Go service builds as a static binary and never needs a shell. Which family fits best, and how do you debug it when it misbehaves?
Show answer
Use a multi-stage build that copies the binary into distroless static, running as non-root. For debugging, build a variant from the :debug tag, which adds a busybox shell, and keep it out of production.