This commit is contained in:
parent
8fedd48f21
commit
51b82e0338
25
Dockerfile
25
Dockerfile
|
|
@ -1,23 +1,36 @@
|
||||||
FROM golang:1.22 AS builder
|
# ✅ 构建阶段,基于 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
|
WORKDIR /app
|
||||||
|
|
||||||
# 只复制 go.mod(不要求 go.sum 存在)
|
# 只复制 go.mod(不要求 go.sum 存在)
|
||||||
COPY go.mod ./
|
COPY go.mod ./
|
||||||
|
|
||||||
# 自动下载基础依赖并生成 go.sum
|
|
||||||
RUN go mod tidy
|
RUN go mod tidy
|
||||||
|
|
||||||
# 再复制完整项目代码
|
# 再复制完整项目代码
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# 再执行一次 tidy(捕捉全部 import 依赖)
|
|
||||||
RUN go mod tidy
|
RUN go mod tidy
|
||||||
|
|
||||||
# 编译可执行文件(保留 CGo 支持)
|
# 编译可执行文件(保留 CGo 支持)
|
||||||
RUN go build -o license-server main.go
|
RUN go build -o license-server main.go
|
||||||
|
|
||||||
# ✅ 运行镜像:改为 debian 支持 CGo 二进制
|
# ✅ 运行镜像:仍用 debian:bullseye-slim,GLIBC 匹配构建阶段
|
||||||
FROM debian:bullseye-slim
|
FROM debian:bullseye-slim
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue