Docker容器内更新apt-get国内加速实现过程

 更新时间:2026年03月01日 10:25:46   作者:Amewin  
文章讲述了使用国内镜像加速Docker容器内apt-get的方法,通过修改配置文件指向国外镜像源,解决了网速慢的问题

Docker容器内更新源apt-get

由于不使用国内镜像网速缓慢,所以使用国内镜像加速就很必要了,但是经过博主测试大部分apt-get加速都是针对Ubuntu 的,根本解决不了Docker 容器内 apt-get 加速问题。

解决过程

进过博主反复尝试终于找到了解决方案。

#1.进入容器
docker exec -it <容器名称/id> bash
#2.执行命令apt-get update 发现缓慢
#3.进入apt-get 配置目录
cd /


/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

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • Docker部署SQL Server及最佳应用小结

    Docker部署SQL Server及最佳应用小结

    SQL Server是由Microsoft开发和推广的关系数据库管理系统(DBMS),本文总结了容器环境下的部署及实践应用,需要的朋友可以参考下
    2022-08-08
  • docker环境下安装jenkins容器的详细教程

    docker环境下安装jenkins容器的详细教程

    这篇文章主要介绍了docker环境下安装jenkins容器的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-05-05
  • Docker环境运行Vue项目全过程

    Docker环境运行Vue项目全过程

    这篇文章主要介绍了Docker环境运行Vue项目全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2025-06-06
  • 如何通过 Docker 部署 AstrBot支持lmstudio本地模型接入

    如何通过 Docker 部署 AstrBot支持lmstudio本地模型接入

    这篇文章给大家介绍如何通过Docker部署AstrBot支持lmstudio本地模型接入,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2026-03-03
  • 详解如何干净的卸载docker的方法

    详解如何干净的卸载docker的方法

    这篇文章主要介绍了详解如何干净的卸载docker的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-09-09
  • 使用docker部署java项目运行环境的实现步骤

    使用docker部署java项目运行环境的实现步骤

    本文主要介绍了使用docker部署java项目运行环境的实现步骤,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-01-01
  • Docker Compose国内镜像一键部署dify教程

    Docker Compose国内镜像一键部署dify教程

    文章描述了如何将克隆的代码进入Docker目录,修改`.env`文件中的部分配置,并创建`dify.yaml`文件来指定国内镜像,部署完成后,通过浏览器访问`192.168.1.223:1880`即可,这是个人经验总结,旨在为读者提供参考
    2026-01-01
  • 蘑菇街 私有云Docker实例应用

    蘑菇街 私有云Docker实例应用

    这篇文章主要介绍了蘑菇街 私有云Docker实例应用的相关资料,需要的朋友可以参考下
    2016-10-10
  • Docker Kill/Pause/Unpause命令使用与区别小结

    Docker Kill/Pause/Unpause命令使用与区别小结

    本文详细介绍了Docker中的三个重要命令,kill、pause和unpause,这些命令在管理和操作运行中的容器时非常有用,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03
  • IDEA集成Docker实现一键部署的详细过程

    IDEA集成Docker实现一键部署的详细过程

    这篇文章主要介绍了IDEA集成Docker实现一键部署,Docker基于Windows集成IDEA,本文分步骤通过图文实例代码相结合给大家介绍的非常详细,需要的朋友可以参考下
    2022-08-08

最新评论