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