这是一个Golang应用的Dockerfile,使用下面的配置可以在构建时进行加速
ARG GO_VERSION=1.21.6
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/golang:1.22.5 AS builder
RUN mkdir -p /api
WORKDIR /api
ENV GOPROXY=https://goproxy.cn,direct
COPY . .
RUN go build -o ./build-app main.go
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/alpine:3.14
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
WORKDIR /
COPY --from=builder /api/build-app /app
RUN chmod +x /app
EXPOSE 8080
ENTRYPOINT ["/app"]
您也可以改造项目旧的dockerfile文件进行适配加速