要点
- 多级镜像打包
COPY --from
RUN
命令加参数.FROM golang:1.13.3 as basic
WORKDIR /
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .
FROM alpine:latest
ENV projectName=supplier
ENV GIN_MODE=release
WORKDIR /$projectName/
COPY --from=basic app .
COPY gateway.yml .
RUN chmod +X app
CMD ["./app"]
踩坑
使用 GOPROXY
指定了GOPROXY
后,发现使用了代理,编译速度有很大提升。ENV GOPROXY="https://mirrors.aliyun.com/goproxy/"
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app .