Files
soul-yongping/soul-api/deploy/Dockerfile
Alex-larget 6df1736e1e 1
2026-03-20 14:47:37 +08:00

41 lines
1.1 KiB
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.

# soul-api Docker 镜像
# 多阶段构建:编译 Go 二进制 → 精简运行镜像
# 构建:在 soul-api 根目录执行 docker build -f deploy/Dockerfile -t soul-api:latest .
# 运行:见 docker-compose.production.yml
# ========== 阶段 1编译 ==========
# 使用本地已缓存的 golang:1.25deploy.py 加 --pull=false 避免拉取
FROM golang:1.25 AS builder
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git && rm -rf /var/lib/apt/lists/*
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" -o /build/soul-api ./cmd/server
# ========== 阶段 2运行 ==========
# 使用标准引用 alpine:3.19,配合 --pull=false 可使用本地已缓存的镜像
FROM alpine:3.19
RUN apk add --no-cache ca-certificates tzdata wget
ENV TZ=Asia/Shanghai
RUN adduser -D -g '' appuser
WORKDIR /app
COPY --from=builder /build/soul-api .
COPY certs/ /app/certs/
ARG ENV_FILE=.env.production
COPY ${ENV_FILE} /app/.env
RUN mkdir -p /app/uploads && chown -R appuser:appuser /app
USER appuser
EXPOSE 8080
ENTRYPOINT ["./soul-api"]