一般对于安装软件加速时,我们大多数会选择阿里云,而对于aspnetcore2.0这个进项来说,由于使用的是Debian操作系统,所有我们要找到它对应的mirror列表,下面是我整理的一个sources.list加速列表,我们把它放在和Dockerfile相同的位置,在Dockerfile生成镜像时把它复制到里面去,替换之前的apt-update地址源即可。
source.list内容
deb http://mirrors.aliyun.com/debian wheezy main contrib non-free deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free
然后我们对Dockerfile进行一些修改,在生成镜像时把它复制到镜像里
FROM microsoft/aspnetcore:2.0 ARG source COPY sources.list /etc/apt/sources.list RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone RUN apt-get update && apt-get -y install libgdiplus WORKDIR /app EXPOSE 80 COPY ${source:-obj/Docker/publish} . ENTRYPOINT ["dotnet", "SMS.dll"]
然后我们再去生成镜像,就会非常非常快了!
当然,你也可以不添加这个文件,而直接把文本覆盖到原来的source.list文件里
FROM microsoft/aspnetcore:2.0 ARG source RUN echo "deb http://mirrors.aliyun.com/debian wheezy main contrib non-free \ deb-src http://mirrors.aliyun.com/debian wheezy main contrib non-free \ deb http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian wheezy-updates main contrib non-free \ deb http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free \ deb-src http://mirrors.aliyun.com/debian-security wheezy/updates main contrib non-free" > /etc/apt/sources.list RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone RUN apt-get update && apt-get install libgdiplus -y WORKDIR /app EXPOSE 80 COPY ${source:-obj/Docker/publish} . ENTRYPOINT ["dotnet", "Pilipa.SMS.dll"]
上面的做法也是完全没有问题的!
你要是在阿里云服务器上,那就是内网对内网,更快!
本文转自博客园张占岭(仓储大叔)的博客,原文链接:docker~aspnetcore2.0镜像安装软件的加速器,如需转载请自行联系原博主。