泽加武 2 months ago
parent
commit
9e7322a861
1 changed files with 11 additions and 3 deletions
  1. 11 3
      Dockerfile

+ 11 - 3
Dockerfile

@@ -1,10 +1,14 @@
-# 使用基于 Alpine 的 Go 镜像作为构建阶段
+# 使用基于 Alpine 的 Go 镜像
 FROM golang:1.23-alpine AS builder
 
 # 设置工作目录
 WORKDIR /app
 
-# 使用 apk 安装 SQLite 的开发依赖
+# 替换国内镜像源
+RUN echo "https://mirrors.aliyun.com/alpine/v3.16/main" > /etc/apk/repositories && \
+    echo "https://mirrors.aliyun.com/alpine/v3.16/community" >> /etc/apk/repositories
+
+# 安装 SQLite 的开发依赖
 RUN apk add --no-cache gcc g++ musl-dev sqlite-dev
 
 # 设置 Go 模块代理(可选,用于国内环境)
@@ -23,7 +27,11 @@ COPY . .
 RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o main cmd/main.go
 
 # 使用轻量级的运行镜像
-FROM alpine:latest
+FROM alpine:3.16
+
+# 替换国内镜像源
+RUN echo "https://mirrors.aliyun.com/alpine/v3.16/main" > /etc/apk/repositories && \
+    echo "https://mirrors.aliyun.com/alpine/v3.16/community" >> /etc/apk/repositories
 
 # 安装 SQLite 的运行时依赖
 RUN apk add --no-cache sqlite-libs ca-certificates