✦ For everyone, free.

Practical knowledge for real and everyday life

Home

4.2.1 FROM

A focused guide to FROM, connecting core concepts with practical Docker and container operations.

FROM is the instruction that begins every Dockerfile, specifying the base image a new image is built on top of, and it is the only instruction that can also start an entirely new build stage within a multi-stage Dockerfile.

Basic Usage

The most common use of FROM simply names a base image to start from, optionally including a specific tag to pin the exact version used.

FROM python:3.12-slim

Every subsequent instruction in the Dockerfile builds on top of whatever filesystem and metadata this base image already provides.

FROM Scratch

FROM scratch is a special case that starts from an entirely empty filesystem, used for images that need nothing beyond what later instructions explicitly add, typically for statically compiled binaries.

FROM scratch
COPY app /app
ENTRYPOINT ["/app"]
Multiple FROM Instructions for Multi-Stage Builds

A single Dockerfile can include multiple FROM instructions, each one starting a new, independent build stage, optionally named for later reference.

FROM golang:1.22 AS build
WORKDIR /src
COPY . .
RUN go build -o app .

FROM debian:bookworm-slim
COPY --from=build /src/app /usr/local/bin/app
CMD ["app"]

Here, the first FROM starts a build stage with the full Go toolchain, while the second starts an entirely separate final stage, copying only the compiled binary across from the first.

Pinning FROM References Precisely

Specifying a base image by a vague or floating tag risks the base changing unexpectedly between builds; pinning to a specific version, or a content digest, produces more predictable and reproducible results.

FROM python:3.12.3-slim@sha256:abcdef...
Why FROM Matters as the Starting Point

Because FROM determines the entire foundation every other instruction builds upon, it is the single instruction with the broadest influence over an image's final characteristics — its size, included tooling, compatibility, and security posture all trace back to this initial choice.

Content in this section