Multi-stage builds let you compile in one (fat) image and
copy the artifact into a tiny runtime image:
FROM golang:1.22 AS build
WORKDIR /src
COPY . .
RUN go build -o app
FROM gcr.io/distroless/static
COPY --from=build /src/app /app
CMD ["/app"]
The PRIMARY benefit?
A) Faster builds because Go is faster than Alpine.
B) Drastically smaller, more secure final images: no compilers, no
package manager, only the binary.
C) Multi-stage runs the build twice for redundancy.
D) It's required by Docker Hub.Sign in to save your code and track progress across devices.