feat: 添加后端 Dockerfile
- 多阶段构建:golang:1.24-alpine 编译,alpine:3.20 运行 - CGO_ENABLED=0 静态链接,包含 ca-certificates 和时区数据
This commit is contained in:
27
backend/Dockerfile
Normal file
27
backend/Dockerfile
Normal file
@@ -0,0 +1,27 @@
|
||||
# ---- 构建阶段 ----
|
||||
FROM golang:1.26-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 先复制依赖清单,利用 Docker 缓存层
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# 复制源码并构建
|
||||
COPY . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /camtalk ./cmd/server
|
||||
|
||||
# ---- 运行阶段 ----
|
||||
FROM alpine:3.20
|
||||
|
||||
RUN apk add --no-cache ca-certificates tzdata
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# 复制二进制和配置
|
||||
COPY --from=builder /camtalk .
|
||||
COPY config.yaml .
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENTRYPOINT ["./camtalk"]
|
||||
Reference in New Issue
Block a user