✦ For everyone, free.

Practical knowledge for real and everyday life

Home

5.3.1.1 Builder Compile Tools

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

Builder compile tools are the compilers, build systems, and related development tooling installed specifically within a builder stage to transform source code into a final compiled or bundled artifact, with the explicit understanding that this tooling stays confined to the builder stage and never reaches the final image.

Installing Compile Tools in a Builder Stage

A builder stage can freely install whatever compilation tooling its build process actually requires, without needing to weigh the size impact that would matter for a final runtime image.

FROM debian:bookworm AS builder
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    libssl-dev \
    pkg-config
COPY . /src
WORKDIR /src
RUN cmake -B build && cmake --build build
Using a Language-Specific Build Image

Many languages provide dedicated build-oriented base images that already include the necessary compile tooling, avoiding the need to install it manually.

FROM rust:1.78 AS builder
WORKDIR /src
COPY . .
RUN cargo build --release

The rust base image already includes the full Rust toolchain needed for compilation, without any additional installation step required.

Confirming Compile Tools Don't Reach the Final Image

Verifying the final image's base, and the absence of compile tooling within it, confirms the separation between the builder stage's tools and the final runtime environment is actually working as intended.

FROM scratch
COPY --from=builder /src/target/release/myapp /myapp
docker run --rm myapp:1.0 which gcc

This should fail in the final image, since gcc only ever existed within the discarded builder stage.

Why Builder Compile Tools Matter

Confining compile tooling entirely to a builder stage, rather than worrying about minimizing it there, lets a build process use whatever tools it genuinely needs, while still producing a final image completely free of that tooling's size and security footprint.