debian经常被用作构建应用镜像的基础镜像,如微软在构建linux下的dotnetcore基础镜像时,提供了基于debian 8(jessie)和debian 9(stretch)的镜像。
由于这些镜像采用的官方包源在国内的访问速度问题,我们在基于aspnet或者dotnet构建镜像时,通常需要将其替换为国内的包源,从而提升镜像构建的速度和成功率。
故障原因
Debian安装软件过程中会使用美国源 security.debian.org。浪潮云连接这个节点网速巨慢。(10K/S以内)
解决方案
软件包源的配置文件在基础镜像所用的Linux系统中路径为 /etc/apt/sources.list
,我们只需在执行 apt-get update
命令之前,
# 更新阿里云的wheezy版本包源 RUN echo "deb http://mirrors.aliyun.com/debian wheezy main contrib non-free" > /etc/apt/sources.list && \ echo "deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free" >> /etc/apt/sources.list && \ echo "deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free" >> /etc/apt/sources.list && \ echo "deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free" >> /etc/apt/sources.list && \ echo "deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free" >> /etc/apt/sources.list && \ echo "deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free" >> /etc/apt/sources.list
上述配置针对采用阿里云提供的debian 7(wheezy)的镜像源,如果采用jessie或者stretch的系统,可以替换wheezy关键词即可。
如果采用网易提供的镜像源,将上述地址替换为:
将我们编写好的使用网易包源的配置文件进行替换就行了。
使用网易包源的配置文件:
sources.list
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
Dockerfile:
FROM microsoft/dotnet:2.1-aspnetcore-runtime WORKDIR /app COPY . . RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && mv sources.list /etc/apt/ && apt-get update -y && apt-get install -y libgdiplus && apt-get clean && ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll EXPOSE 80 ENTRYPOINT ["dotnet", "Alipay.Demo.PCPayment.dll"]
主要是这两句命令:
#备份旧的配置文件 mv /etc/apt/sources.list /etc/apt/sources.list.bak #替换为我们自定义的配置文件 mv sources.list /etc/apt/
需要注意的是,sources.list 需要放在我们打包的目录,保证能复制到镜像里面。
然后构建时间由12分钟缩短到37秒,这个过程是没有使用Docker Cache所花的时间:
其他加速
使用内网的腾讯云包源配置文件:
deb http://mirrors.tencentyun.com/debian/ jessie main non-free contrib deb http://mirrors.tencentyun.com/debian/ jessie-updates main non-free contrib deb http://mirrors.tencentyun.com/debian/ jessie-backports main non-free contrib deb-src http://mirrors.tencentyun.com/debian/ jessie main non-free contrib deb-src http://mirrors.tencentyun.com/debian/ jessie-updates main non-free contrib deb-src http://mirrors.tencentyun.com/debian/ jessie-backports main non-free contrib deb http://mirrors.tencentyun.com/debian-security/ jessie/updates main non-free contrib deb-src http://mirrors.tencentyun.com/debian-security/ jessie/updates main non-free contrib
阿里云作为一个全球第三的云平台运营商,也是具有此项服务的。其包源地址为:https://mirrors.aliyun.com
配置文件:
deb https://mirrors.aliyun.com/debian/ jessie main non-free contrib deb https://mirrors.aliyun.com/debian/ jessie-updates main non-free contrib deb https://mirrors.aliyun.com/debian/ jessie-backports main non-free contrib deb-src https://mirrors.aliyun.com/debian/ jessie main non-free contrib deb-src https://mirrors.aliyun.com/debian/ jessie-updates main non-free contrib deb-src https://mirrors.aliyun.com/debian/ jessie-backports main non-free contrib deb https://mirrors.aliyun.com/debian-security/ jessie/updates main non-free contrib deb-src https://mirrors.aliyun.com/debian-security/ jessie/updates main non-free contrib
Debian7
deb http://mirrors.163.com/debian/ wheezy main non-free contrib deb http://mirrors.163.com/debian/ wheezy-updates main non-free contrib deb http://mirrors.163.com/debian/ wheezy-backports main non-free contrib deb-src http://mirrors.163.com/debian/ wheezy main non-free contrib deb-src http://mirrors.163.com/debian/ wheezy-updates main non-free contrib deb-src http://mirrors.163.com/debian/ wheezy-backports main non-free contrib deb http://mirrors.163.com/debian-security/ wheezy/updates main non-free contrib deb-src http://mirrors.163.com/debian-security/ wheezy/updates main non-free contrib
Debian8
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
热评文章
相关阅读
已有1位网友发表了看法: