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.

21 lines
485 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 mod tidy 来同步和清理模块依赖
1 month ago
RUN --mount=type=cache,target=/go/pkg/mod \ go mod tidy
1 month ago
# 编译可执行文件
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"]