1. 程式人生 > >docker~aspnetcore2.0鏡像安裝軟件的加速器

docker~aspnetcore2.0鏡像安裝軟件的加速器

lin erl copy sof one 阿裏雲服務 找到 雲服務 main

一般對於安裝軟件加速時,我們大多數會選擇阿裏雲,而對於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鏡像安裝軟件的加速器