You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
541 B

1 month ago
# 使用最小化的基础镜像 (Alpine)
1 month ago
FROM golang:1.21-alpine AS builder
1 month ago
1 month ago
# 设置工作目录
1 month ago
WORKDIR /workspace
1 month ago
1 month ago
# 将代码复制到容器内(你也可以选择在构建过程中通过挂载代码)
COPY . .
1 month ago
1 month ago
# 设置 Go 模块缓存和构建缓存目录
ENV GOMODCACHE=/go/pkg/mod
ENV GOCACHE=/go/cache
# 执行 go mod tidy 来同步和清理模块依赖
RUN go mod tidy
# 编译可执行文件
RUN go build -o myapp -ldflags "-X main.RunMode=test -s -w"
# 暴露容器端口
1 month ago
EXPOSE 11000
1 month ago
1 month ago
# 运行应用程序
1 month ago
CMD ["./myapp"]