Files
AIRouter/backend/Dockerfile
2025-11-10 22:23:42 +08:00

42 lines
865 B
Docker
Raw Permalink 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.
# 第一阶段:构建 Go 应用
FROM golang:1.24-bookworm AS builder
WORKDIR /app
# 复制 go.mod 和 go.sum 文件
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制所有源代码
COPY . .
# 编译应用程序
# CGO_ENABLED=1 是因为 SQLite 驱动需要 CGO
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o main .
# 第二阶段:创建最小化的运行镜像
FROM debian:bookworm-slim
WORKDIR /app
# 安装运行时依赖SQLite 需要)
RUN apt-get update && apt-get install -y \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# 从构建阶段复制编译好的二进制文件
COPY --from=builder /app/main .
# 创建数据目录
RUN mkdir -p /app/data
# 暴露后端服务端口
EXPOSE 8080
# 设置默认的数据库路径环境变量
ENV DB_PATH=/app/data/gateway.db
# 启动应用
CMD ["./main"]