3.3 Base Images
A focused guide to Base Images, connecting core concepts with practical Docker and container operations.
Base images are the starting point of any Dockerfile, specified through the FROM instruction, providing the foundational filesystem and tooling that every subsequent layer in an image is built on top of.
What a Base Image Provides
A base image typically provides, at minimum, a minimal operating system filesystem and, depending on the specific base chosen, a language runtime, package manager, or other foundational tooling the rest of the build depends on.
FROM python:3.12-slim
This base image provides a minimal Debian-derived filesystem along with the Python 3.12 interpreter already installed, ready for application-specific layers to build on top of it.
Choosing an Appropriate Base Image
The right base image depends on what the application actually needs: a full-featured base with broad tooling for flexibility during development, or a minimal base for a smaller, more secure production image.
FROM python:3.12
FROM python:3.12-slim
FROM python:3.12-alpine
These three options trade off size and included tooling differently, despite all providing the same Python version, which is why base image choice is rarely a one-size-fits-all decision.
Starting From an Empty Base
For statically compiled binaries with no runtime dependencies, a base image is not strictly necessary at all — scratch provides an effectively empty starting point.
FROM scratch
COPY app /app
ENTRYPOINT ["/app"]
Pinning Base Image Versions
Specifying a base image by a vague tag like a major version alone risks the base image changing unexpectedly between builds; pinning to a specific version, or even a specific digest, produces more predictable, reproducible builds.
FROM python:3.12.3-slim@sha256:abcdef...
Why Base Image Choice Matters
The base image is the single decision with the broadest downstream effect on an image's final size, available tooling, and security exposure — every subsequent layer inherits whatever the base image already includes, making this choice worth deliberate consideration rather than a default left unexamined.