A container image built FROM ubuntu ships an operating system's worth of software to run one process. The shell, the package manager, coreutils and a dozen libraries your application never imports all land in production, appear in your vulnerability scans and are available to an attacker who gets a shell. Minimal and distroless images invert that: they hold the application and its runtime dependencies and little else.
The idea is old: attack surface grows with installed code. Containers make it actionable in a way traditional servers never did. A VM accretes packages over years; a container image is rebuilt from a declarative recipe on every commit. That means you can choose, precisely and repeatably, what ends up inside.
The range from full OS to nothing
- Full distro (
ubuntu,debian). Familiar, easy to debug, and the largest attack surface. Hundreds of packages, a shell, a package manager an attacker can use to pull tools. - Minimal distro (
alpine,debian-slim). A fraction of the size. Alpine swaps glibc for musl, which occasionally breaks binaries but removes a lot of surface. - Distroless. Google's distroless images contain your app, its runtime libraries, CA certificates and timezone data, and no shell, no package manager, no
ls. There is almost nothing for an attacker to pivot with. scratch. The empty image. A statically-linked Go or Rust binary can run in it with literally nothing else present. It has the smallest possible surface and no on-box debugging.
Distroless suits most teams: it is small and gives an attacker little to work with, yet it still carries the CA bundle (and libc, in the base and cc variants) that applications need. Chainguard's Wolfi pushes the same idea further, rebuilding minimal images frequently so they aim to ship with no known CVEs on the day you pull them.
The 'no shell' objection
The most common pushback is operational: 'How do I kubectl exec into a distroless container to debug it?' You do not, and that is the point, because an attacker cannot either. The modern answer is kubectl debug with an ephemeral debug container, which attaches a throwaway image carrying your tools into the target pod's namespaces without baking those tools into the production image. You attach debugging tools on demand instead of shipping them permanently.
Getting there with multi-stage builds
The mechanism that makes distroless practical is the multi-stage build. A fat 'builder' stage compiles the app with its full toolchain; a lean final stage copies only the resulting artifact onto a distroless or scratch base. The compiler, the build dependencies and the intermediate files never reach production.
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app ./cmd/server
FROM gcr.io/distroless/static:nonroot
COPY --from=build /app /app
USER nonroot
ENTRYPOINT ["/app"] # no shell, no apt, nothing to pivot with
Pin the base image by digest rather than a floating tag, so a rebuild is reproducible and an upstream change cannot silently alter what you ship. Combine that with a scanner in CI, and 'minimal' stops being a one-time cleanup and becomes a property the pipeline maintains.
Smaller images pull faster, cost less to store and give an intruder almost nothing to work with. The discipline helps only the images you build this way. The forgotten service still running a three-year-old full-distro image carries your unpatched CVEs, and you cannot slim down what you have not found.