# ✅ 构建阶段,基于 debian:bullseye,自己装 Go,保证 GLIBC 匹配运行阶段 FROM debian:bullseye AS builder # 安装 Go 和编译依赖 RUN apt-get update && apt-get install -y \ wget \ git \ gcc \ libc6-dev \ sqlite3 \ ca-certificates # 安装 Go 1.22(或你需要的版本) RUN wget https://golang.org/dl/go1.22.0.linux-amd64.tar.gz && \ tar -C /usr/local -xzf go1.22.0.linux-amd64.tar.gz && \ ln -s /usr/local/go/bin/go /usr/local/bin/go ENV PATH="/usr/local/go/bin:$PATH" WORKDIR /app # 只复制 go.mod(不要求 go.sum 存在) COPY go.mod ./ RUN go mod tidy # 再复制完整项目代码 COPY . . RUN go mod tidy # 编译可执行文件(保留 CGo 支持) RUN go build -o license-server main.go # ✅ 运行镜像:仍用 debian:bullseye-slim,GLIBC 匹配构建阶段 FROM debian:bullseye-slim RUN apt-get update && apt-get install -y \ ca-certificates \ sqlite3 \ curl \ && rm -rf /var/lib/apt/lists/* WORKDIR /root/ COPY --from=builder /app/license-server . HEALTHCHECK --interval=60s --timeout=3s --start-period=10s --retries=3 CMD curl -f http://localhost:13579/api/health || exit 1 EXPOSE 13579 CMD ["./license-server"]