在写dockerfile时替换国内源

众所周知,Debian是linux发行版中官方源最难用的一个,这个傻逼源让我再构建docker镜像时卡了很久。

​ 那么能不能替换构建dockerfile时使用的源呢?显然是可以的

​ 在与Dockerfile同级的目录中准备一个sources.list(系统版本要对应,这里是Debian11),把里面的源换成比较快的国内源,另外版本代号也要跟镜像对应起来

Debian11(bullseye)的国内源(https://blog.csdn.net/weixin_48646819/article/details/120139802):

#http://mirrors.163.com/debian/为软件源也可以为其他的 bullseye为版本代号 main non-free contrib区别如下
deb http://mirrors.163.com/debian/ bullseye main non-free contrib

deb http://mirrors.163.com/debian/ bullseye-updates main non-free contrib

deb http://mirrors.163.com/debian/ bullseye-backports main non-free contrib

deb-src http://mirrors.163.com/debian/ bullseye main non-free contrib

deb-src http://mirrors.163.com/debian/ bullseye-updates main non-free contrib

deb-src http://mirrors.163.com/debian/ bullseye-backports main non-free contrib

#deb http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib

#deb http://mirrors.ustc.edu.cn/debian-security/ bullseye/updates main non-free contrib

#deb-src http://mirrors.163.com/debian-security/ bullseye/updates main non-free contrib

#deb-src http://mirrors.ustc.edu.cn/debian-security/ bullseye/updates main non-free contrib

deb http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib

deb-src http://mirrors.ustc.edu.cn/debian-security/ stable-security main non-free contrib

在Dockerfile中,使用类似如下代码,在apt update之前替换掉软件源即可:

FROM debian:bullseye

# Add custom china source,ADD可将本地文件添加到镜像中,类似于具有root权限的cp命令
ADD sources.list /etc/apt/ 
posted @ 2021-11-13 11:31  dayceng  阅读(3561)  评论(0编辑  收藏  举报