Files
ChatRoom/Dockerfile
2026-02-03 23:45:27 +08:00

38 lines
749 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.23-alpine AS builder
# 设置工作目录
WORKDIR /app
# 安装必要的构建工具
RUN apk add --no-cache gcc musl-dev
# 复制依赖文件并下载
COPY go.mod go.sum ./
RUN go mod download
# 复制源代码
COPY . .
# 编译应用
# CGO_ENABLED=0 用于生成静态二进制文件,适合在 alpine 运行
RUN CGO_ENABLED=0 GOOS=linux go build -o server ./cmd/server/main.go
# 第二阶段:运行
FROM alpine:latest
WORKDIR /app
# 从构建阶段复制二进制文件
COPY --from=builder /app/server .
# 复制静态资源文件
COPY --from=builder /app/web ./web
# 暴露端口(默认 2779
EXPOSE 2779
# 运行应用(通过 PORT 环境变量可覆盖)
ENV PORT=2779
CMD ["./server"]