Docker容器内更新源apt-get的方法
由于不使用国内镜像网速缓慢,所以使用国内镜像加速就很必要了,但是经过博主测试大部分apt-get加速都是针对Ubuntu 的,根本解决不了Docker 容器内 apt-get 加速问题。
进过博主反复尝试终于找到了解决方案。
#1.进入容器
docker exec -it <容器名称/id> bash
#2.执行命令apt-get update 发现缓慢
#3.进入apt-get 配置目录
cd /ect/apt
#4.执行备份命令 --避免修改失败无法使用
cp sources.list sources.list.bak
#5.同时执行echo下的4行命令,修改成国内镜像源
echo "">sources.list
echo "deb http://ftp2.cn.debian.org/debian/ buster main">>sources.list
echo "deb http://ftp2.cn.debian.org/debian/debian-security buster/updates main">>sources.list
echo "deb http://ftp2.cn.debian.org/debian/debian buster-updates main">>sources.list
#6.查看文件 是否修改成功
cat sources.list
###############################
root@62be94cc90e7:/etc/apt# cat sources.list
deb http://ftp2.cn.debian.org/debian/ buster main
deb http://ftp2.cn.debian.org/debian/debian-security buster/updates main
deb http://ftp2.cn.debian.org/debian/debian buster-updates main
root@62be94cc90e7:/etc/apt#
###############################
#7.更新apt-get
apt-get update
#修改完成
#如果发现安装vim 缓慢或者失败,说明本教程不适合你
apt-get install vim
#将备份完成的文件改回来,即可。
rm sources.list
mv sources.list.bak sources.list
说明
修改的原理是使用【地址】
https://www.debian.org/mirror/list
在别的国家地区也是可以使用该方法加速,将配置改成所在地区网址即可。
root@62be94cc90e7:/etc/apt# apt-get update
Get:1 http://mirrors.tuna.tsinghua.edu.cn/debian buster InRelease [122 kB]
Ign:2 http://mirrors.tuna.tsinghua.edu.cn/debian/debian-security buster/updates InRelease
Ign:3 http://mirrors.tuna.tsinghua.edu.cn/debian/debian buster-updates InRelease
Err:4 http://mirrors.tuna.tsinghua.edu.cn/debian/debian-security buster/updates Release
404 Not Found [IP: 101.6.8.193 80]
Get:6 http://mirrors.tuna.tsinghua.edu.cn/debian buster/main amd64 Packages [7906 kB]
Err:5 http://mirrors.tuna.tsinghua.edu.cn/debian/debian buster-updates Release
404 Not Found [IP: 101.6.8.193 80]
Reading package lists... Done
E: The repository 'http://ftp2.cn.debian.org/debian/debian-security buster/updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: The repository 'http://ftp2.cn.debian.org/debian/debian buster-updates Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
详细文档(避免新手出错)
#进入容器
docker exec -it <容器名称/id> bash
#执行命令apt-get 发现缓慢
apt-get update
#执行命令 Ctrl + C 停止 返回命令行
cd /ect/apt
#查看目录
ls
root@62be94cc90e7:/etc/apt# ls
apt.conf.d auth.conf.d preferences.d sources.list sources.list.d trusted.gpg.d
#执行备份命令 --避免修改失败无法使用,备份可恢复
cp sources.list sources.list.bak
#执行命令 更改apt-get 不用安装vim (vim真的太慢了)
echo "">sources.list
echo "deb http://ftp2.cn.debian.org/debian/ buster main">>sources.list
echo "deb http://ftp2.cn.debian.org/debian/debian-security buster/updates main">>sources.list
echo "deb http://ftp2.cn.debian.org/debian/debian buster-updates main">>sources.list
#更改完成后执行命令
apt-get update
#将备份完成的文件改回来,即可。
#rm --删除文件后使用 mv --更改文件名字
rm sources.list
mv sources.list.bak sources.list