Dockerfile:
1 2 3 4 5 6 |
RUN data="" \ && for s in $(wget -qO- http://mirrors.aliyun.com/alpine/MIRRORS.txt); do t=$(time -f "%E" wget -T1 -q $s/MIRRORS.txt -O /dev/null 2>&1) && echo "$s was $t" && data="$data$t $s\n"; done \ && echo -e $data | sort \ && newrepo=`echo -e $data | sort | head -2 | tail -1 | awk '{print $3}'` \ && repo=${newrepo//\//\\/} \ && sed -i 's/http:\/\/dl-cdn.alpinelinux.org\/alpine\//'"$repo"'/g' /etc/apk/repositories |
shell,其实就是上面run里的内容了
1 2 3 4 5 6 7 8 9 10 |
data="" for s in $(wget -qO- http://mirrors.aliyun.com/alpine/MIRRORS.txt); do t=$(time -f "%E" wget -T1 -q $s/MIRRORS.txt -O /dev/null 2>&1) echo "$s was $t" && data="$data$t $s\n" done echo -e $data | sort newrepo=`echo -e $data | sort | head -2 | tail -1 | awk '{print $3}'` repo=${newrepo//\//\\/} sed -i 's/http:\/\/dl-cdn.alpinelinux.org\/alpine\//'"$repo"'/g' /etc/apk/repositories |
shell没学过,边百度边写的,比较烂请轻喷,有更快速的写法请留言指出,谢谢~
wget设置了1秒超时,如果服务器本身网络比较卡,可以调大几秒
搜索最快mirror代码来源:
https://wiki.alpinelinux.org/wiki/Finding_the_fastest_mirror