# Use official Go image as build environment FROM golang:1.24-alpine AS builder # Set working directory inside the container WORKDIR /app # Copy go.mod and go.sum first (for caching dependencies) COPY go.mod go.sum ./ # Download dependencies (cached if no changes) RUN go mod download # Copy the rest of the source code COPY . . # Build the Go app statically linked for Alpine RUN CGO_ENABLED=0 GOOS=linux go build -o main # Start a new minimal image to run the app FROM alpine:latest # Install ca-certificates for HTTPS calls (if needed) RUN apk --no-cache add ca-certificates # Copy the binary from builder COPY --from=builder /app/main /main # Expose port your app listens on EXPOSE 8080 # Run the binary CMD ["./main"]