✦ For everyone, free.

Practical knowledge for real and everyday life

Home

5.3.1 Builder Stage

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

A builder stage is a Dockerfile stage, defined in a multi-stage build, dedicated specifically to compiling, bundling, or otherwise preparing an application, typically using a larger base image containing the full set of development tools needed for that work, with no expectation that this stage itself will be part of the final image.

Defining a Builder Stage

A builder stage is given a name through AS, making it referenceable by later stages that need to copy specific artifacts out of it.

FROM golang:1.22 AS builder
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o app .
What Makes a Stage a "Builder" Specifically

A builder stage typically uses a base image with substantially more tooling than the final runtime image would need — compilers, build systems, development headers — tooling whose only purpose is producing the final artifact, not running it.

FROM golang:1.22 AS builder
FROM scratch
COPY --from=builder /src/app /app

The contrast between these two stages' base images reflects the fundamentally different purposes each one serves.

A Builder Stage Never Needs to Be Minimized

Because a builder stage's content never appears in the final image (assuming nothing copies its full filesystem across), there is little reason to worry about its own size — only the size of whatever specific artifacts get copied from it into later stages actually matters.

FROM golang:1.22 AS builder
RUN apt-get install -y build-essential cmake

Installing additional, possibly substantial tooling here has no bearing on the final image's size, as long as only the compiled output is copied forward.

Why the Builder Stage Concept Matters

Recognizing a stage's specific role as a builder — separate from runtime concerns entirely — clarifies why its size and tooling choices can be made freely, focused purely on producing correct build output as efficiently as possible, without the size constraints that matter for a final runtime image.

Content in this section