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.
31 lines
649 B
31 lines
649 B
# 使用最小化的基础镜像 (Alpine)
|
|
FROM golang:1.21-alpine AS builder
|
|
|
|
# 设置工作目录
|
|
WORKDIR /workspace
|
|
|
|
# 将代码复制到容器内
|
|
COPY . .
|
|
|
|
# 设置 Go 模块缓存和构建缓存目录
|
|
ENV GOMODCACHE=/go/pkg/mod
|
|
ENV GOCACHE=/go/cache
|
|
|
|
# 编译可执行文件
|
|
RUN go mod tidy && go build -o myapp -ldflags "-X main.RunMode=test -s -w"
|
|
|
|
# 使用更小的基础镜像运行编译后的可执行文件
|
|
FROM alpine:latest
|
|
|
|
# 创建工作目录
|
|
WORKDIR /app
|
|
|
|
# 复制编译后的可执行文件到新的镜像
|
|
COPY --from=builder /workspace/myapp /app/
|
|
|
|
# 暴露容器端口
|
|
EXPOSE 11000
|
|
|
|
# 设置容器启动命令
|
|
CMD ["/app/myapp"]
|