Multi-stage builds: compile big, ship small
Select an icon to see what it is.
Step 1 of 6
One Dockerfile, two stages
The Dockerfile has two FROM lines. The first, named builder, uses a full Go image. The second starts from alpine, and only what it copies in will ship.
$ docker build -t web:1.0 . PrevNext
Dockerfile (read by BuildKit through the build session)
FROM golang:1.22 AS builderWORKDIR /srcCOPY . .RUN CGO_ENABLED=0 go build -o /out/web .FROM alpineCOPY --from=builder /out/web /webCMD ["/web"]