Back to questions
JuniorTheoryVery common
What ends up in the image built from this Dockerfile?
FROM golang:1.23 AS build
WORKDIR /src
COPY . .
RUN CGO_ENABLED=0 go build -o /app .
FROM gcr.io/distroless/static-debian12
COPY --from=build /app /app
ENTRYPOINT ["/app"]The distroless base and the /app binary; the Go compiler and the sources stay behind in the build stage
- Expecting every stage's layers in the final image — only the last stage ships
- Thinking
COPY --from=buildcopies the whole stage rather than the path it names
- Why does the Go build set
CGO_ENABLED=0before running ondistroless/static? - How do you build only the
buildstage, for example to run tests in it?