Files
go-micro-service/Dockerfile
Mads Smed 0215bdd6a6
Some checks failed
Build & Push Docker Image / build-and-push (push) Has been cancelled
sd
2025-11-23 16:38:18 +01:00

36 lines
735 B
Docker

# ------------------------------------------------------------
# 1. Build stage
# ------------------------------------------------------------
FROM golang:1.25-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
# Dependencies first (cache friendly)
COPY go.mod go.sum ./
RUN go mod download
# Copy the entire codebase
COPY . .
# Build for the architecture of the host (ARM64 runner)
RUN CGO_ENABLED=0 go build -o server .
# ------------------------------------------------------------
# 2. Final minimal runtime image
# ------------------------------------------------------------
FROM alpine:3.20
RUN adduser -D -g '' appuser
WORKDIR /app
COPY --from=builder /app/server .
EXPOSE 8080
USER appuser
CMD ["./server"]