3.3.3.4 Base Image Packages
A focused guide to Base Image Packages, connecting core concepts with practical Docker and container operations.
Base image packages are the software already installed in a chosen base image before any application-specific layers are added, determining both what additional installation steps are necessary and how much unnecessary, unused software the final image might carry.
Inspecting What a Base Image Already Includes
Before adding redundant installation steps, it is useful to check what a base image already provides, since installing something already present wastes build time and adds unnecessary duplicate layers.
docker run --rm python:3.12-slim dpkg -l | head -30
This lists packages already installed in the base image, which is a reasonable starting point before deciding what else genuinely needs to be added.
Minimal Bases Include Fewer Default Packages
A more minimal base image, by design, includes fewer pre-installed packages, meaning more needs to be explicitly added for anything beyond the bare essentials — a deliberate tradeoff between starting size and the explicit installation work required afterward.
FROM alpine:3.19
RUN apk add --no-cache ca-certificates tzdata
Even commonly assumed-present utilities like timezone data may need explicit installation on a sufficiently minimal base image.
Avoiding Unnecessary Default Packages
Some base image variants include packages that a given application will never actually use — documentation, locale data, optional utilities — which can be removed if they meaningfully affect image size and are confirmed unnecessary.
RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
The --no-install-recommends flag avoids pulling in additional, often unnecessary packages that a package manager would otherwise install alongside the explicitly requested one.
Why Auditing Base Image Packages Matters
Understanding exactly what a chosen base image already includes — and what it does not — informs both what additional installation steps a Dockerfile actually needs, and what unnecessary software might be worth actively avoiding for the sake of a smaller, more auditable final image.
docker run --rm myapp:1.0 dpkg -l