Static Go binary, CGO_ENABLED=0
A static Go binary contains the code and runtime dependencies needed for execution without relying on dynamically loaded C libraries. Setting CGO_ENABLED=0 disables CGO during compilation and allows compatible Go dependencies to produce a binary suitable for the distroless static runtime.
Minimal example
FROM golang:1.27 AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /out/api ./cmd/apiLearn this concept
Lesson 7.1 · Multi-stage Dockerfiles for GoPrerequisite conceptsGo modules