Docker容器内ubuntu更新apt-get 国内加速
前言
由于不使用国内镜像网速缓慢,所以使用国内镜像加速就很必要了,但是经过博主测试大部分apt-get加速都是针对Ubuntu 的,根本解决不了Docker 容器内 apt-get 加速问题。
进过博主反复尝试终于找到了解决方案。
感谢https://blog.csdn.net/weixin_44552215/article/details/108780410
具体办法
cpp
#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下的行命令,修改成国内镜像源
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
echo "">>sources.list
echo "deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial universe">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties">>sources.list
echo "deb http://archive.canonical.com/ubuntu xenial partner">>sources.list
echo "deb-src http://archive.canonical.com/ubuntu xenial partner">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted">>sources.list
echo "deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe">>sources.list
echo "deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse">>sources.list
#6.查看文件 是否修改成功
cat sources.list
###############################
root@62be94cc90e7:/etc/apt# cat sources.list
root@62be94cc90e7:/etc/apt#
###############################
#7.更新apt-get
apt-get update
#修改完成
#如果发现安装vim 缓慢或者失败,说明本教程不适合你
apt-get install vim
#将备份完成的文件改回来,即可。
rm sources.list
mv sources.list.bak sources.list