container-schulung/listings/visitcounter/app/Containerfile
yberion 1ac9851e48 Initial commit: Schulungsunterlagen Tag 2 + Setup-Script
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 18:50:58 +02:00

18 lines
864 B
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ── Stage 1: Kompilieren ─────────────────────────────────────────────────────
FROM golang:1.24-alpine AS builder
WORKDIR /build
COPY main.go go.mod ./
# go mod tidy lädt Abhängigkeiten und erzeugt go.sum im Build-Layer
# CGO_ENABLED=0 → statisch gelinktes Binary, keine libc-Abhängigkeit
RUN go mod tidy \
&& CGO_ENABLED=0 GOOS=linux \
go build -ldflags="-s -w" -o visitcounter .
# ── Stage 2: Minimales Laufzeit-Image ────────────────────────────────────────
FROM scratch
# scratch = leeres Image ohne OS das Binary läuft direkt auf dem Kernel
COPY --from=builder /build/visitcounter /visitcounter
EXPOSE 8080
USER 65534
ENTRYPOINT ["/visitcounter"]