Choosing a base image
Full, slim, Alpine, distroless, hardened or scratch: what each base image puts under your app and what it costs in size, compatibility and debugging.
Choosing a base image
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- The base image sets your image's floor for size, its C library, its package manager, what tools exist for debugging, and how many CVEs you inherit.
- Full images such as python:3.14 carry compilers and build tools. The slim variant of the same Python is about a tenth the size and is the usual default for running apps.
- Alpine is small because it uses musl libc and BusyBox. Binaries and wheels built for glibc may not run on it, and some behaviour, from DNS to memory allocation, differs.
- Distroless images keep only what the app needs to run: no shell and no package manager. They are small and hard to attack, and you debug them from outside.
- scratch is empty. It suits statically linked binaries, which then need their own CA certificates, time zone data and a non-root user entry.
- Whatever you pick, pin it and rebuild often, because a base image's fixes reach you only when you rebuild on top of it.
Everything under the FROM line
FROM python:3.14 looks like a choice of language. It’s a choice of operating system too. Everything that image contains ships with your app: its C library, its shell, its package manager, its compilers, its CA certificates and every known vulnerability in all of them. The base sets a floor on image size, which tools you have when something breaks at 2 a.m., and how much your security scanner will complain.
Think of it as buying a flat furnished or empty. Furnished is ready to live in and full of things you’ll never use. Empty is clean but you’ll need to bring a kettle.
The options, measured
I pulled the linux/amd64 manifest of each image from its registry and summed the compressed layer sizes, which is what a pull downloads:
| Image | Layers | Compressed size |
|---|---|---|
python:3.14 (full, Debian 13) |
7 | 416.2 MB |
python:3.14-slim |
4 | 43.5 MB |
python:3.14-alpine (Alpine 3.24) |
4 | 17.8 MB |
gcr.io/distroless/python3-debian13 |
48 | 22.6 MB |
cgr.dev/chainguard/python |
11 | 28.2 MB |
debian:trixie |
1 | 49.4 MB |
debian:trixie-slim |
1 | 29.8 MB |
ubuntu:latest (26.04) |
2 | 42.2 MB |
alpine:latest (3.24.4) |
1 | 3.9 MB |
busybox:latest |
1 | 2.2 MB |
gcr.io/distroless/static-debian13 |
13 | 0.86 MB |
cgr.dev/chainguard/static |
1 | 0.46 MB |
The full Python image is nearly ten times the slim one, because it’s built on Debian’s buildpack-deps with compilers and development headers so pip install can build anything. That’s useful in a build stage and dead weight at run time, which is where multi-stage builds come in.
Slim: the usual default
-slim variants are Debian with only the runtime packages. You keep glibc, apt, a shell and the behaviour every prebuilt binary and Python wheel expects. For most apps, slim is the sensible default: small enough, compatible, debuggable.
Alpine: small, and different
Alpine is small because it’s built differently. I unpacked the alpine:latest layer: 16 packages in total, with musl 1.2.6 as the C library and busybox providing the shell and core commands (/bin/sh is a symlink to /bin/busybox). That difference is the trade:
- musl isn’t glibc. Binaries built against glibc don’t run. Python wheels need
musllinuxbuilds, and where none exists pip compiles from source. That’s the slow, dependency-hungry build people hit with numpy or cryptography. - Behaviour differs. musl’s DNS resolver, its memory allocator and its locale support aren’t glibc’s. Older musl lacked DNS-over-TCP fallback until 1.2.4, a famous source of Kubernetes DNS bugs. Performance-sensitive apps sometimes run slower.
- The win shrinks. Once your app’s dependencies are added, a 4 MB base against a 30 MB one is rarely the biggest item in the image.
Alpine shines for small tools, static-ish binaries and images where every megabyte is pulled thousands of times.
Distroless and hardened images
Distroless images, started by Google, keep only what an app needs at run time. I unpacked gcr.io/distroless/static-debian13: /bin and /usr/bin are empty, with no shell and no package manager. It does contain a CA bundle at /etc/ssl/certs/ca-certificates.crt, time zone data, and an /etc/passwd with three users: root, nobody and nonroot (UID 65532). The config sets User to 0, root. You opt into the unprivileged user with the :nonroot tag or a USER line. Variants exist for glibc programs (base), Python, Java and Node.
Hardened images follow the same idea with a vendor promise: Chainguard’s images, Docker Hardened Images (whose community tier is free under Apache 2.0 from dhi.io), and others rebuild constantly, ship SBOMs and provenance, and aim for near-zero known CVEs.
The cost is debugging. docker exec -it app sh fails because there’s no sh. You debug from outside with docker debug or a sidecar, as in the interactive lesson.
scratch: nothing at all
FROM scratch is an empty filesystem, for a statically linked binary from Go, Rust or similar. You must bring everything the binary expects: CA certificates for TLS, /usr/share/zoneinfo if it handles time zones, and a passwd entry if you want a named non-root user. distroless/static is effectively scratch with those three added, which is why it’s usually the better choice.
A way to decide
- Default to the slim variant of your language’s official image.
- Need smaller and tighter, and the app is static or simple? distroless or a hardened image, with a full image in the build stage.
- Go or Rust static binary?
distroless/staticorscratch. - Alpine when you’ve tested your dependencies on musl and the size matters.
- Whatever you pick: pin the tag (and digest in production), rebuild regularly so base fixes reach you, and scan the result, which scanning images covers.
About the video
The embed is a clip of XtendedGreg’s “The 5MB Lie — Why Docker Alpine Is (and Isn’t) the Answer”, September 2026, from 21:03 to 32:23, 11 minutes. The clip covers four of the video’s chapters: alternatives beyond Alpine and Debian, a decision framework for which base image to use, what Alpine gets right, and the summary and checklist. The earlier half, on musl’s design, when Alpine breaks, the CVE argument and the build-on-Debian, run-on-Alpine pattern, is linked in deeper. English was judged from its “English (US) original” audio and manual English captions. CyberJAR’s video in deeper compares distroless, scratch and slim with tests on Go and Java.
What was run: every size in the table is the sum of compressed layer sizes from the amd64 manifests on Docker Hub, gcr.io and cgr.dev, fetched with a short Python client. The alpine:latest and distroless/static-debian13 layers were downloaded and unpacked to read the package database, /bin, /etc/passwd and the certificate bundle. Nothing was built or run. The musl DNS history and the hardened-image licensing are from the musl and Docker docs, checked 2026-11-28.
Where this fits
Base images come from somewhere. Next, the registries that serve them: Docker Hub and other registries.
Check yourself
A Python app with numpy builds in seconds on python:3.14-slim but compiles for many minutes on python:3.14-alpine. Why?
pip finds prebuilt glibc (manylinux) wheels for slim. On Alpine it needs musllinux wheels, and if a version has none it builds from source, which needs compilers and headers in the image.
Your Go service is statically linked and runs on FROM scratch, but every HTTPS call fails with a certificate error. What's missing?
CA certificates. scratch has no /etc/ssl/certs, so copy a CA bundle in, or use distroless static, which includes ca-certificates, tzdata and a passwd file.
Why might a team choose debian-slim over Alpine even though Alpine is smaller?
glibc compatibility with prebuilt binaries and wheels, familiar apt tooling and fewer surprises in DNS and performance. After a few layers of dependencies, the size difference often stops mattering.
Distroless images have almost no CVEs. Why is that not the whole security story?
The app and its own dependencies still carry vulnerabilities, the image still needs regular rebuilds as fixes land, and the user, capabilities and secrets handling matter as much as the base.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.