Files
toutoukan/Dockerfile
2025-09-16 01:21:02 +08:00

22 lines
754 B
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.
# 阶段1编译 Go 程序(使用 Go 1.24 系列的 alpine 镜像,自动拉取最新小版本)
FROM golang:1.24-alpine AS builder
WORKDIR /app
# 复制依赖文件
COPY go.mod go.sum ./
# 国内代理加速依赖下载(可选但推荐)
ENV GOPROXY=https://goproxy.cn,direct
# 下载依赖
RUN go mod download
# 复制代码并编译(关闭 CGO 确保镜像可移植)
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o main .
# 阶段2构建轻量级运行镜像
FROM alpine:3.18
WORKDIR /app
# 从编译阶段复制二进制文件
COPY --from=builder /app/main .
# 可选:配置时区(避免日志时间异常)
RUN apk add --no-cache tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 启动程序
CMD ["./main"]