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