配置全自动docker版本部署

This commit is contained in:
2026-07-24 21:04:02 +08:00
parent 699a9e3b92
commit 137f506367
13 changed files with 571 additions and 127 deletions
+47
View File
@@ -0,0 +1,47 @@
# ============================================================
# 构建阶段
# ============================================================
FROM golang:1.21-alpine AS builder
WORKDIR /app
# 复制依赖文件
COPY go.mod go.sum ./
RUN go mod download
# 复制源码(确保 bin/ 和 static/ 目录存在)
COPY . .
# 编译 Linux 版(CGO_ENABLED=0 保证静态编译)
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-s -w" \
-o frpc-console .
# ============================================================
# 运行阶段
# ============================================================
FROM alpine:latest
# 安装 ca-certificates 和 tzdata(确保 HTTPS 和时区正常)
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /app
# 从构建阶段复制编译好的二进制
COPY --from=builder /app/frpc-console /app/frpc-console
# 创建数据目录(用于持久化 db 和日志)
RUN mkdir -p /app/data
# 暴露端口(默认 9300
EXPOSE 9300
# 环境变量
ENV PORT=9300
ENV TZ=Asia/Shanghai
# 数据卷(持久化数据库、配置、日志)
VOLUME ["/app/data"]
# 启动
ENTRYPOINT ["/app/frpc-console"]