Guides / Containers

Choosing a Docker base image: Debian slim, Alpine, distroless or scratch

beginnerUpdated 26 Nov 2026942 words

The base image decides much of what a vulnerability scanner finds in your image and how hard it is to debug a running container. There is no single right choice; the facts below help to pick one per application.

What each option contains

Full distribution images (debian:trixie, ubuntu:24.04): a minimal installation of the distribution with a shell, the package manager and the core utilities. Familiar to work with, and more packages than an application needs.

Slim variants (debian:trixie-slim, python:3.13-slim): Debian with documentation, man pages and some locales removed. Still a shell and apt. The official Python, Node.js and Ruby images have -slim tags built on it.

Alpine (alpine:3.24, node:24-alpine): a small distribution built on musl libc and BusyBox, with the package manager apk.

Distroless (gcr.io/distroless/static-debian13, base-debian13, cc-debian13, python3-debian13, java21-debian13, nodejs24-debian13 and others): Debian packages without a package manager or shell. The README says they "do not contain package managers, shells or any other programs you would expect to find in a standard Linux distribution". As of November 2026 they are based on Debian 13.

scratch: the empty image. It holds only the files you copy in.

How many packages a scanner sees

Fewer packages mean fewer findings to read and fewer reasons to rebuild. Counted in November 2026 with the package manager of each image:

Image OS release Packages
debian:bookworm-20261027-slim Debian 12 88 (dpkg-query -W)
python:3.13-slim Debian 13 87 (dpkg-query -W), plus Python
alpine:3.24.3 Alpine 3.24 16 (apk info)

A distroless static image holds CA certificates, time zone data, a /tmp directory and an /etc/passwd entry; base adds glibc and libssl. scratch holds nothing. Your application adds its own dependencies on top in every case; a Python or Node.js application often brings more packages through pip or npm than the base image has.

The count is not the risk. A finding in a library your program never loads matters less than one in OpenSSL, which almost every network service uses. But every package is a line in the scanner report that someone has to read.

musl and glibc

Alpine uses musl libc; Debian, Ubuntu, RHEL and distroless base use glibc. Most software works on both, with some differences to know:

  • Binaries compiled against glibc do not run on Alpine as they are. Build them on Alpine, or link them statically.
  • Python packages with C extensions ship prebuilt wheels for glibc (manylinux) and, where the project publishes them, for musl (musllinux, defined in PEP 656). Without a musl wheel, pip compiles the package during the build, which needs a compiler in the build stage and takes longer.
  • Go programs built with CGO_ENABLED=0 are static and run on any base, including scratch and distroless static.

Measured in the images above: ldd --version in debian:bookworm-20261027-slim prints GLIBC 2.36, and ldd in alpine:3.24.3 prints musl libc (x86_64) Version 1.2.6.

Support periods

A base image gets fixes only while its release is supported. Alpine supports each branch in its main repository for about two years, Debian for about three years plus LTS, Ubuntu LTS for five years of standard support. The dates per release are in End-of-life dates of Linux releases. Distroless images follow Debian; the README says that images without a Debian version in the name "will currently select -debian13 images, but that will change in the future". Pin the variant with the Debian version (static-debian13) so the switch happens when you decide.

Debugging without a shell

The trade-off of distroless and scratch is that docker exec -it app sh does not work. There are ways around it.

  • Distroless images have :debug tags with a BusyBox shell. Use them for a debugging session, not in production.
  • Start a second container in the namespaces of the first. With docker run --rm -it --pid=container:app --network=container:app alpine:3.24 sh you see the processes and network of app, and its files under /proc/1/root/ (as far as permissions allow).
  • Log enough that you rarely need a shell.

Multi-stage builds

Whatever the final base, build in a full image and copy only the result:

FROM golang:1.27-bookworm AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -trimpath -o /out/server ./cmd/server

FROM gcr.io/distroless/static-debian13:nonroot
COPY --from=build /out/server /server
ENTRYPOINT ["/server"]

The compiler, the source code and the build tools stay in the first stage and never reach production. The nonroot tag runs the program as UID 65532.

Which one to pick

Application A good start
Static Go or Rust binary distroless static, or scratch with CA certificates and time zone data copied in
Python, Node.js, Ruby the -slim variant of the official language image; Alpine if the dependencies have musl builds
PHP the official php image (Debian) or its -alpine variant
Java a JRE image on Debian or Ubuntu, or distroless java
Something that needs many system tools debian:trixie-slim or ubuntu:24.04
A tool you docker exec into often a slim or full image, since you need the shell

Use the same base family across your images where you can. Then all images share package names and install commands, and a fix in the base reaches all of them with the next rebuild.

Sources

Check your servers every day

The agent of Patchbrief reports the packages and settings of a server once a day; the digest names what to fix first.

Start free