Containers and Kubernetes · Intermediate · 20 min
Choose a container base image: slim, Alpine, distroless or scratch
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · Skopeo 1.21 (Ubuntu archive) · Syft 1.57.2 · Grype 0.122.1
You will download four Python base images once, measure their size, packages, known vulnerabilities, C library and shell with Skopeo, Syft and Grype, and end with a comparison table you can use to pick a base for your own service.
On this page
The FROM line is the first decision in a Dockerfile and the one that is hardest to see the cost of. The base image sets how much every server and CI job downloads, which C library your code links against, how many packages a scanner reports, and whether you can open a shell when something breaks at 2 a.m.
You do not need Docker to compare base images. A registry serves an image as a set of compressed layers plus a small JSON config, so a few command-line tools can download and examine those files directly. In this tutorial you compare four candidates for a Python 3.15 service:
python:3.15-slim, the Docker official image on Debian 13 with most extras removedpython:3.15-alpine, the Docker official image on Alpine Linux, which uses musl instead of glibcgcr.io/distroless/python3-debian13:nonroot, Google's distroless image: Debian packages but no shell or package managercgr.dev/chainguard/python:latest, Chainguard's free image built on Wolfi, a minimal glibc distribution
The fifth option in the title, scratch, is an empty image. You cannot run Python on it, and the last step explains where it fits.
You download each image once and analyse it offline. That keeps the comparison cheap on metered or prepaid data, and it avoids the anonymous pull limits that Docker Hub applies.
Step 1 · Install Skopeo, Syft and Grype
Skopeo copies and inspects images in registries without a container daemon. Syft lists the packages inside an image, and Grype matches that list against vulnerability databases. Install Skopeo and the helpers from the Ubuntu archive:
sudo apt update
sudo apt install -y skopeo jq curl ca-certificates python3-venv zstdSyft and Grype move faster than the archive, so install the release binaries from GitHub and check them against the published checksums. dpkg --print-architecture prints amd64 or arm64, which matches the release file names:
mkdir -p ~/base-image-demo/downloads
cd ~/base-image-demo/downloads
ARCH=$(dpkg --print-architecture)
SYFT=1.57.2
GRYPE=0.122.1
curl -fsSLO "https://github.com/anchore/syft/releases/download/v${SYFT}/syft_${SYFT}_linux_${ARCH}.tar.gz"
curl -fsSLO "https://github.com/anchore/syft/releases/download/v${SYFT}/syft_${SYFT}_checksums.txt"
curl -fsSLO "https://github.com/anchore/grype/releases/download/v${GRYPE}/grype_${GRYPE}_linux_${ARCH}.tar.gz"
curl -fsSLO "https://github.com/anchore/grype/releases/download/v${GRYPE}/grype_${GRYPE}_checksums.txt"
sha256sum --ignore-missing -c "syft_${SYFT}_checksums.txt"
sha256sum --ignore-missing -c "grype_${GRYPE}_checksums.txt"
tar -xzf "syft_${SYFT}_linux_${ARCH}.tar.gz" syft
tar -xzf "grype_${GRYPE}_linux_${ARCH}.tar.gz" grype
sudo install -m 755 syft grype /usr/local/bin/Binaries in /usr/local/bin get no updates from apt upgrade. To upgrade later, change the two version numbers and run the block again.
Check it worked
skopeo --version
syft version
grype versionEach sha256sum line printed OK, and the version commands print something like skopeo version 1.21.0, Version: 1.57.2 and Version: 0.122.1.
Step 2 · Download the four candidates once
Copy each image into a local folder in the OCI layout, a standard on-disk format of JSON files and layer blobs. The global flags --override-os linux --override-arch amd64 pick the amd64 variant of each multi-platform image, so the numbers are comparable even if you run this on an arm64 machine:
cd ~/base-image-demo
mkdir -p images
skopeo --override-os linux --override-arch amd64 copy --quiet docker://docker.io/library/python:3.15-slim oci:images/slim:latest
skopeo --override-os linux --override-arch amd64 copy --quiet docker://docker.io/library/python:3.15-alpine oci:images/alpine:latest
skopeo --override-os linux --override-arch amd64 copy --quiet docker://gcr.io/distroless/python3-debian13:nonroot oci:images/distroless:latest
skopeo --override-os linux --override-arch amd64 copy --quiet docker://cgr.dev/chainguard/python:latest oci:images/wolfi:latestEvery later step reads these folders, so nothing else in this tutorial downloads image layers again.
Check it worked
du -sh images/*You see four folders, each a few tens of megabytes. Inside each one, index.json points at a manifest, and blobs/sha256/ holds the manifest, the config and the compressed layers.
Step 3 · Compare size and runtime settings
skopeo inspect reads the manifest and config. LayersData lists each layer with its compressed size, which is what a server downloads on a cold pull:
cd ~/base-image-demo
for n in slim alpine distroless wolfi; do
skopeo inspect "oci:images/$n:latest" | jq -r --arg n "$n" '"\($n): \([.LayersData[].Size] | add / 1e6 | . * 10 | round / 10) MB in \(.LayersData | length) layers, created \(.Created)"'
doneWhen checked in November 2026, the amd64 images came to something like 44 MB for slim, 20 MB for Alpine, 23 MB for distroless and 28 MB for the Wolfi image. Your figures will differ a little, because all four are rebuilt often.
Next, look at how each image expects to run. --config prints the image config, which holds the entrypoint, default command and user:
for n in slim alpine distroless wolfi; do
skopeo inspect --config "oci:images/$n:latest" | jq -c --arg n "$n" '{image: $n, user: .config.User, entrypoint: .config.Entrypoint, cmd: .config.Cmd}'
doneCheck it worked
Two differences stand out. The two Docker official images have no user, so they run as root unless your Dockerfile adds USER. Distroless :nonroot and the Wolfi image run as user 65532 out of the box. Also look at the distroless entrypoint: it is /usr/bin/python3.13, because distroless packages Debian 13's own Python, not 3.15. Your code and any compiled packages must target the Python version the base image ships.
Finally, the distroless created date reads 1970-01-01. Distroless builds are reproducible and set a fixed timestamp, so that field tells you nothing about freshness. You will use digests for that in the last step.
Step 4 · Count the packages with Syft
Every package in a base image is something you inherit: a scanner reports its vulnerabilities, and you have to rebuild when it is patched. Generate a software bill of materials (SBOM) for each image. The oci-dir: prefix tells Syft to read the local folder:
cd ~/base-image-demo
mkdir -p sbom
for n in slim alpine distroless wolfi; do
syft scan "oci-dir:images/$n" --quiet -o "syft-json=sbom/$n.json"
doneCount the packages, and split them by type so you can see where they come from:
for n in slim alpine distroless wolfi; do
jq -r --arg n "$n" '"\($n): \(.artifacts | length) packages (\([.artifacts[].type] | group_by(.) | map("\(.[0])=\(length)") | join(", ")))"' "sbom/$n.json"
doneCheck it worked
Each line shows a total and a breakdown such as deb=..., apk=... or python=.... Slim lists the most, because it carries a working Debian userland: apt, dpkg, bash, perl-base and their libraries. The distroless and Wolfi images list far fewer. Slim's Python is compiled from source into /usr/local, so Syft finds it by inspecting the binary rather than from the package database.
Step 5 · Scan for known vulnerabilities with Grype
Grype reads the SBOMs, so it does not touch the images again. It downloads its vulnerability database on the first run. Update it explicitly so you can see the download happen:
grype db update
grype db status
du -sh ~/.cache/grypeScan each SBOM and save the results as JSON:
cd ~/base-image-demo
mkdir -p vulns
for n in slim alpine distroless wolfi; do
grype "sbom:sbom/$n.json" --quiet -o json > "vulns/$n.json"
doneSummarise by severity, and count how many matches have a fix available. A finding with no fixed version is one you cannot clear by rebuilding:
for n in slim alpine distroless wolfi; do
jq -r --arg n "$n" '"\($n): \(.matches | length) matches, \([.matches[] | select(.vulnerability.fix.state == "fixed")] | length) fixable (\([.matches[].vulnerability.severity] | group_by(.) | map("\(.[0])=\(length)") | join(", ")))"' "vulns/$n.json"
doneCheck it worked
grype db status reports a valid database with a recent build date, and each image prints a line of counts. Expect slim to show the most matches, many of them Negligible or Low and many without a fix, since Debian triages minor issues and does not patch all of them. The minimal images usually show few or none. A count of zero means "no known matches today", not "secure": scan again on every build, as covered in the Trivy tutorial.
Step 6 · Check the C library and the shell
Two properties decide whether your code runs and whether you can debug it: which C library the image uses, and whether it has a shell. Both show up in the file list. Write a short script that lists every file in an image's layers:
cd ~/base-image-demo
cat > list-files.sh <<'SH'
#!/usr/bin/env bash
# Usage: ./list-files.sh images/<name> Writes images/<name>.files
set -euo pipefail
dir=$1
manifest=$(jq -r '.manifests[0].digest' "$dir/index.json" | cut -d: -f2)
for layer in $(jq -r '.layers[].digest' "$dir/blobs/sha256/$manifest" | cut -d: -f2); do
tar -tf "$dir/blobs/sha256/$layer"
done | sed 's|^\./||' | sort -u > "$dir.files"
SH
chmod +x list-files.sh
for n in slim alpine distroless wolfi; do ./list-files.sh "images/$n"; done
wc -l images/*.filesGNU tar detects gzip and zstd compression by itself, which is why zstd was in the install list. Now look for a dynamic loader (it names the C library), a shell and the Python binary:
for n in slim alpine distroless wolfi; do
echo "== $n"
grep -E '(ld-musl-x86_64\.so\.1|ld-linux-x86-64\.so\.2)$' "images/$n.files" || echo "no dynamic loader found"
grep -E '^(usr/)?bin/(sh|bash|ash|dash)$' "images/$n.files" || echo "no shell"
grep -E 'bin/python3\.[0-9]+$' "images/$n.files" || echo "no versioned python binary"
doneCheck it worked
Alpine is the only one with ld-musl-x86_64.so.1; the other three use glibc's ld-linux-x86-64.so.2. Slim and Alpine have a shell (dash and BusyBox ash), while distroless and the Wolfi latest image have none. The Python binary is python3.15 in the two official images and python3.13 in distroless; the Wolfi image carries whatever Python is current in Wolfi.
What these mean in practice:
- musl and wheels. Python packages with compiled code ship wheels tagged
manylinuxfor glibc andmusllinuxfor musl. If a package has no musllinux wheel, pip on Alpine falls back to compiling from source, which needs a compiler in the build stage and makes builds slow. The next step shows how to check your own dependencies. - musl at run time. musl's DNS resolver, locale support and memory allocator behave differently from glibc's in some cases. Most services never notice, but a lookup that works on slim and fails on Alpine is a known class of bug.
- No shell. You cannot
docker execorkubectl execinto distroless or Wolfilatestto look around. Distroless publishes:debugtags with a BusyBox shell, and Chainguard publisheslatest-dev. On Kubernetes you can attach a temporary debug container to a running pod instead:
kubectl debug -it <pod-name> --image=busybox:1.37 --target=<container-name>Replace <pod-name> and <container-name> with your own. The debug container shares the pod's process namespace, so you can inspect the app without adding tools to its image.
Step 7 · Check your dependencies have musl wheels
Before you choose Alpine, ask PyPI whether every package you depend on publishes a musllinux wheel for Python 3.15. pip download can fetch wheels for a platform other than the one you are on, and --only-binary=:all: makes it fail instead of falling back to source. Use a throwaway virtual environment so the system Python stays untouched:
cd ~/base-image-demo
python3 -m venv venv
cat > requirements.txt <<'REQ'
orjson==3.13.0
psycopg-binary==3.3.9
REQ
venv/bin/pip download --quiet --only-binary=:all: \
--platform musllinux_1_2_x86_64 --python-version 3.15 --implementation cp --abi cp315 \
-r requirements.txt -d wheels-musl
ls wheels-muslFor your own service, replace requirements.txt with your real pinned list. If you deploy to arm64 (aarch64) servers, repeat with musllinux_1_2_aarch64.
Check it worked
ls shows two files ending in cp315-musllinux_1_2_x86_64.whl. If a package had no such wheel, pip would stop with something like ERROR: Could not find a version that satisfies the requirement, and that package is the one that would be compiled on Alpine.
Step 8 · Build your comparison table and decide
Put the measurements side by side with one script:
cd ~/base-image-demo
cat > compare.sh <<'SH'
#!/usr/bin/env bash
set -euo pipefail
cd ~/base-image-demo
printf '%-11s %6s %9s %8s %8s %6s %6s %s\n' IMAGE MB PACKAGES MATCHES FIXABLE SHELL LIBC PYTHON
for n in slim alpine distroless wolfi; do
mb=$(skopeo inspect "oci:images/$n:latest" | jq '[.LayersData[].Size] | add / 1e6 | . * 10 | round / 10')
pkgs=$(jq '.artifacts | length' "sbom/$n.json")
matches=$(jq '.matches | length' "vulns/$n.json")
fixable=$(jq '[.matches[] | select(.vulnerability.fix.state == "fixed")] | length' "vulns/$n.json")
if grep -qE '^(usr/)?bin/(sh|bash|ash|dash)$' "images/$n.files"; then shell=yes; else shell=no; fi
if grep -q 'ld-musl-' "images/$n.files"; then libc=musl; else libc=glibc; fi
py=$(grep -m1 -oE 'python3\.[0-9]+$' "images/$n.files" || echo "?")
printf '%-11s %6s %9s %8s %8s %6s %6s %s\n' "$n" "$mb" "$pkgs" "$matches" "$fixable" "$shell" "$libc" "$py"
done
SH
chmod +x compare.sh
./compare.shThen record the digest of each download. A digest changes whenever the publisher rebuilds, so re-running this in a week and comparing tells you how often each image is refreshed, which the distroless created date cannot:
for n in slim alpine distroless wolfi; do
echo "$(date +%F) $n $(jq -r '.manifests[0].digest' "images/$n/index.json")"
done | tee -a ~/base-image-digests.logTo pin a base image in a Dockerfile, use the digest of the multi-platform index, which is the SHA-256 of the raw manifest the registry returns. This command fetches only that small index manifest, not the layers:
skopeo inspect --raw docker://gcr.io/distroless/python3-debian13:nonroot | sha256sumYou would then write FROM gcr.io/distroless/python3-debian13:nonroot@sha256:<digest> and let a tool such as Renovate or Dependabot propose updates. Pin container images by digest covers the full workflow.
Check it worked
compare.sh prints one row per image with size, packages, vulnerability matches, fixable matches, shell, C library and Python version. Read it against these rules of thumb:
- Slim is the safe default. glibc means every manylinux wheel works, there is a shell and
aptfor system libraries, and it tracks Python releases. Pay for that with the biggest download and the longest scanner report. AddUSERyourself, as shown in Run containers as a non-root user. - Alpine is the smallest official option. Choose it when the wheel check passes for all your dependencies and you can test DNS and locale behaviour. Avoid it when you depend on packages that only ship manylinux wheels.
- Distroless gives glibc with no shell, no package manager and a non-root user by default. The catch for Python is that you get Debian's Python (3.13 on Debian 13), so build your virtual environment in a stage with the same Python version and copy it across. Keep the
:debugtag for emergencies. - Wolfi (Chainguard) is minimal, glibc-based and rebuilt often, usually with the fewest scanner matches. The free tier only serves
latestandlatest-dev, so you cannot pin a Python minor version by tag. Pin by digest, and expect the Python version to move when Wolfi moves. There is no support agreement on the free images. - Scratch is empty: no libc, no certificates, no time zone data, no
/etc/passwd. It suits a single static binary, such as a Go program built withCGO_ENABLED=0. It cannot run Python. For a static binary, distrolessstaticis usually the better choice because it adds certificates, time zone data and a non-root user. The Snip series builds exactly that.
The size column is paid on every pull: each new node and each CI job without a warm cache downloads the image again. A smaller image means less transfer on metered or slow links and faster cold starts when an autoscaler adds nodes.
When you have your answer, remove the downloads and the digest log:
cd ~
rm -rf ~/base-image-demo
rm -f ~/base-image-digests.logIf you do not use Syft or Grype elsewhere, also remove the binaries from /usr/local/bin and the Grype vulnerability database:
sudo rm -f /usr/local/bin/syft /usr/local/bin/grype
rm -rf ~/.cache/grypeNext steps
- Use the base you picked in a two-stage build with Make Docker images smaller with multi-stage builds.
- Add a scanner gate to your pipeline with Scan container images for vulnerabilities with Trivy.
- Go deeper on SBOMs with Generate an SBOM for a container image with Syft.
- Lock the base you chose to an exact build with Pin container images by digest.
Related tutorials
- Validate Kubernetes manifests before they reach a clusterYou will have one script that checks plain, Kustomize, Helm, generated and custom-resource manifests against the Kubernetes 1.37 schemas and a set of lint rules, with no cluster, and a GitHub Actions job that runs it on every pull request.
- Use secrets in Docker builds without leaking them into the imageYou will find a token and a private key leaking through a Docker build with Trivy 0.76, then fix the build with secret and SSH mounts, carry the fix into Compose and GitHub Actions, and prove with a rescan that the build context is clean.
- Store data in Kubernetes with persistent volumes and claimsYou will claim storage on a Kubernetes 1.37 kind cluster, prove the data outlives its pod, see which access modes and reclaim policies keep or lose data, and know how expansion and snapshots work on a cloud CSI driver.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials