+FROM golang:1.23
+
+WORKDIR /app
+COPY main.go .
+RUN go build -o hello main.go
+
+EXPOSE 8080
+CMD ["./hello"]
+
+
+$ docker image ls hello-single
+REPOSITORY SIZE
+hello-single 838 MB
+
+ Compiler & build tools ship in the final image — never needed at runtime.
+More packages = more vulnerabilities, slower pulls, higher costs.
+
+# Stage 1: Build
+FROM golang:1.23 AS builder
+WORKDIR /app
+COPY main.go .
+RUN CGO_ENABLED=0 go build -o hello main.go
+
+# Stage 2: Minimal runtime
+FROM alpine:3.21
+WORKDIR /app
+COPY --from=builder /app/hello .
+EXPOSE 8080
+CMD ["./hello"]
+
+ golang:1.23 image.alpine:3.21 image.Go toolchain + compiler + sources + app
+
+hello-single 838 MB
+
+ Alpine Linux + compiled binary only
+
+hello-multi 12.1 MB
+
+
+FROM golang:1.23 AS builder
+FROM alpine:3.21 AS runtime
+
+
+# By name (preferred)
+COPY --from=builder /app/hello .
+
+# From an external image
+COPY --from=nginx:latest \
+ /etc/nginx/nginx.conf /nginx.conf
+
+ Copy from any build stage or external image — without including it in the final result.
+
+# Production: run all stages
+$ docker image build \
+ --tag hello-multi:1.0 .
+
+# Dev: stop at the builder stage
+$ docker image build \
+ --target builder \
+ --tag hello-dev:1.0 .
+
+
+REPOSITORY SIZE
+hello-multi 12.1 MB # production
+hello-dev 838 MB # full toolchain
+
+ Production — minimal image, binary only.
+Development — full toolchain, same Dockerfile.
+