Files
Jiao77-Blog/server/Dockerfile
2026-03-01 09:13:24 +08:00

43 lines
765 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.
# 构建阶段
FROM golang:1.21-alpine AS builder
WORKDIR /app
# 安装依赖
RUN apk add --no-cache git gcc musl-dev
# 复制 go.mod 和 go.sum
COPY go.mod go.sum ./
# 下载依赖
RUN go mod download
# 复制源代码
COPY . .
# 构建二进制文件
RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o novablog-server ./cmd/server
# 运行阶段
FROM alpine:latest
WORKDIR /app
# 安装 ca-certificates用于 HTTPS 请求)
RUN apk --no-cache add ca-certificates tzdata
# 从构建阶段复制二进制文件
COPY --from=builder /app/novablog-server .
# 创建数据目录
RUN mkdir -p /app/data
# 暴露端口
EXPOSE 8080
# 设置环境变量
ENV GIN_MODE=release
ENV DB_PATH=/app/data/novablog.db
# 运行
CMD ["./novablog-server"]