duck2api / Dockerfile
smgc's picture
Update Dockerfile
7753c47 verified
raw
history blame
No virus
660 Bytes
# 使用 Go 1.21 官方镜像作为构建环境
FROM golang:1.21 AS builder
# 禁用 CGO
ENV CGO_ENABLED=0
# 设置工作目录
WORKDIR /app
# 复制 go.mod 和 go.sum 并下载依赖
RUN git clone https://github.com/aurora-develop/Duck2api.git .
RUN sed -i'' 's|("/v1|("/api/v1|g' /app/initialize/router.go
RUN go mod download
# 复制源代码并构建应用
RUN go build -ldflags "-s -w" -o /app/duck2api .
# 使用 Alpine Linux 作为最终镜像
FROM alpine:latest
# 设置工作目录
WORKDIR /app
# 从构建阶段复制编译好的应用和资源
COPY --from=builder /app/duck2api /app/duck2api
# 暴露端口
EXPOSE 8080
CMD ["/app/duck2api"]