This commit is contained in:
parent
c8fa58d0e3
commit
18771c745f
18
Dockerfile
18
Dockerfile
|
|
@ -5,10 +5,17 @@ FROM golang:1.26-alpine AS builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
# ✅ 设置 Go 代理(解决网络问题)
|
||||||
|
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
|
||||||
|
ENV GOSUMDB=off
|
||||||
|
ENV GO111MODULE=on
|
||||||
|
|
||||||
RUN apk add --no-cache git make
|
RUN apk add --no-cache git make
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download && go mod verify
|
|
||||||
|
# ✅ 先尝试下载依赖,如果失败则重试
|
||||||
|
RUN go mod download || go mod download
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|
@ -18,13 +25,16 @@ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
|
||||||
.
|
.
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 阶段2: 运行(使用带 Go 的轻量镜像)
|
# 阶段2: 运行
|
||||||
# ============================================================
|
# ============================================================
|
||||||
FROM golang:1.26-alpine AS runner
|
FROM alpine:latest
|
||||||
|
|
||||||
RUN apk add --no-cache git
|
RUN apk add --no-cache ca-certificates tzdata git go
|
||||||
|
|
||||||
ENV TZ=Asia/Shanghai
|
ENV TZ=Asia/Shanghai
|
||||||
|
ENV GOPROXY=https://goproxy.cn,https://proxy.golang.org,direct
|
||||||
|
ENV GOSUMDB=off
|
||||||
|
|
||||||
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
|
||||||
|
|
||||||
RUN adduser -D -g '' appuser
|
RUN adduser -D -g '' appuser
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue