1、使用Alpine基礎鏡像下載軟件包時報錯
Dockerfile
FROM alpine:3.11 RUN apk add --no-cache ca-certificates # To speed up building process, we copy binary directly from make # result instead of building it again, so make sure you run the # following command first before building docker image # make cb-apiserver # COPY cb-apiserver /usr/local/bin/ EXPOSE 9090 CMD ["sh"]
原因:alpine 鏡像默認的軟件倉庫在國外,有時 docker build 的時候安裝軟件包會很慢。
解決方法:使用國內的軟件包鏡像,比如 https://mirrors.ustc.edu.cn 的鏡像:
Dockerfile加上下面這行:
RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.ustc.edu.cn/!g' /etc/apk/repositories
參考:https://mozillazg.com/2020/03/use-alpine-image-common-issues.rst.html
2、go get程序包超時
Dockerfile加上下面這行:
ENV GOPROXY=https://goproxy.cn,direct