Skip to main content
InterviewHubPRO
Section Overview
Q39

Question 39 of 50

Part 4: Production Compilation, Tooling & Senior Engineering (39 - 50)

78%
Golang & Concurrency (50 Qs)•Part 4: Production Compilation, Tooling & Senior Engineering (39 - 50)

Building Minimal Production Docker Images for Go: `scratch` and `distroless`.

mid LevelMost AskedCode ExampleDocker & Containers

In Simple Words: Because Go compiles to a self-contained machine code binary, production Docker images do not require a Linux distribution (Ubuntu/Debian):

dockerfile
# Stage 1: Build binary
FROM golang:1.22-alpine AS builder
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o server .

# Stage 2: Minimal scratch image (~15MB total!)
FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/server /server
ENTRYPOINT ["/server"]