Multi-stage Docker build

Multi-stage Docker builds separate the compilation process from the runtime environment to create smaller, more secure container images.

Use a multi-stage Dockerfile to separate the build environment from the final runtime image, reducing size and excluding build tools. The first stage compiles the Go binary, and the second stage copies only the binary into a minimal image.

# Stage 1: Build
FROM golang:1.23 AS builder
WORKDIR /src
COPY . .
RUN go build -o myapp .

# Stage 2: Runtime
FROM alpine:latest
WORKDIR /root/
COPY --from=builder /src/myapp .
CMD ["./myapp"]