Files
hldrCenter/server/Dockerfile

37 lines
938 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 程序(使用 Go 1.24 官方镜像)
FROM golang:1.24-alpine AS builder
# 设置工作目录(容器内)
WORKDIR /app
# 复制依赖文件,利用 Docker 缓存加速构建
COPY go.mod ./
RUN go mod download
# 复制项目源码
COPY . .
# 编译程序Go 1.24 支持更多优化,保持原命令即可(兼容旧版)
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o myproject main.go
# 第二阶段:构建轻量镜像
FROM alpine:3.20
# 安装必要依赖Go 1.24 编译的程序可能依赖最新的 libc
RUN apk --no-cache add ca-certificates tzdata
# 设置时区(可选)
ENV TZ=Asia/Shanghai
WORKDIR /app
# 复制编译产物和配置文件
COPY --from=builder /app/myproject ./
COPY --from=builder /app/config ./config/
COPY --from=builder /app/database ./database
# 暴露端口(根据你的 config 配置修改)
EXPOSE 8080
# 启动命令
CMD ["./myproject"]