替换 Dockerfile 中的 apt 源来增加 Docker 镜像的构建速度
<!–more–>
操作
首先在 Dockerfile 的路径下添加文件 sources.list 。
https://mirrors.163.com/.help/debian.html
网易源
deb http://mirrors.163.com/debian/ jessie main non-free contrib
deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib
deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib
deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
阿里云源
deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ jessie-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ jessie-backports main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ jessie/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security/ jessie/updates main non-free contrib
腾讯云源
https://mirrors.cloud.tencent.com/help/debian.html
deb http://mirrors.cloud.tencent.com/debian jessie main contrib non-free
deb http://mirrors.cloud.tencent.com/debian jessie-updates main contrib non-free
#deb http://mirrors.cloud.tencent.com/debian jessie-backports main contrib non-free
#deb http://mirrors.cloud.tencent.com/debian jessie-proposed-updates main contrib non-free
deb-src http://mirrors.cloud.tencent.com/debian jessie main contrib non-free
deb-src http://mirrors.cloud.tencent.com/debian jessie-updates main contrib non-free
#deb-src http://mirrors.cloud.tencent.com/debian jessie-backports main contrib non-free
#deb-src http://mirrors.cloud.tencent.com/debian jessie-proposed-updates main contrib non-free
在 Dockerfile 比较开始的位置添加如下内容
ADD sources.list sources.list
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && mv sources.list /etc/apt/
当然为了减少镜像的文件层数,你可以写的更精简一点。
参考资料
Docker 实用技巧之更改软件包源提升构建速度
https://www.cnblogs.com/stulzq/p/9339250.html
Leave a Reply