使用 Alpine 作為基礎鏡像時可能會遇到的常見問題的解決方法


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM