Files
91-api-server/Dockerfile
2026-06-10 02:35:17 +00:00

33 lines
779 B
Docker
Raw 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: Build
# ============================================================
FROM golang:1.24-alpine AS builder
WORKDIR /build
# 依赖缓存层(变更少,利用 Docker 缓存加速)
COPY go.mod go.sum ./
RUN go mod download
# 编译
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o api-server .
# ============================================================
# Stage 2: Runtime
# ============================================================
FROM alpine:3.21
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /app
COPY --from=builder /build/api-server .
# ip2region.xdb 运行时数据目录(卷挂载或 COPY
RUN mkdir -p /app/data
EXPOSE 8080
ENTRYPOINT ["./api-server", "serve"]