Docker容器内更新apt-get 国内加速

2023-05-16

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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Docker容器内更新apt-get 国内加速 的相关文章

随机推荐

  • 关于makefile与CMakeList的理解

    为了编译某一工程中的众多 c文件搞出来一个makefile可以批量编译 xff1b Linux下用Cmake也即CMakeLists txt文件 作者写的很清晰易懂
  • c++版本详表

    1 语言标准 版本代目版本号年份第一版c 43 43 981998第二版c 43 43 032003第三版c 43 43 112011第四版c 43 43 142014第五版c 43 43 172017第六版待定待定 2 visual st
  • ffmpeg常用命令

    1 rtsp into mp4 ffmpeg exe i 34 rtsp username password 64 192 168 1 183 554 34 f mp4 r 25 an 640x480 ss 600 t 600 s 34 t
  • http包详解

    位于应用层的http协议 什么也不多说了 xff0c 马上放个图看看 请求方法 xff0c 主要是 xff1a get xff1a 获取 post xff1a 提交 请求头 xff1a User Agent xff1a 产生请求的浏览器类型
  • linux下编译C++项目

    include CheckCXXCompilerFlag CHECK CXX COMPILER FLAG std 61 c 43 43 11 COMPILER SUPPORTS CXX11 CHECK CXX COMPILER FLAG s
  • www总结

    一 www服务器 1 什么是www xff1a www是world wide web的缩写 xff0c 也就是全球信息广播的意思 通常说的上网就是使用www来查询用户所需要的信息 www可以结合文字 图形 影像以及声音等多媒体 xff0c
  • matlab基础练习作业(1)

    要期末考试了 xff0c 整理一下平时的题 作业 xff11 1 写出完成下列操作的命令 1 将矩阵A第2 5行中第1 3 5列元素赋给矩阵B B 61 A 2 5 1 3 5 或者B 61 A 2 3 4 5 1 3 5 2 删除矩阵A的
  • PHP中使用cURL实现进行Post请求 ssl 双向认证

    span class token comment 64 param string url 接收数据的api 64 param string vars 提交的数据 64 param int second 要求程序必须在 second 秒内完成
  • 大端字节序与小端字节序 (网络字节序与主机字节序)

    大端字节序与小端字节序 1 简介2 判断机器字节序 xff08 C C 43 43 xff09 3 主机字节序与网络字节序的转换4 IP地址与网络字节序的转换 1 简介 字节序分为大端字节序 xff08 big endian xff09 和
  • Noetic安装ros_canopen

    建立workspace mkdir span class token operator span p canopen span class token operator span scr cd canopen catkin make 下载n
  • ROS学习初始化ws下catkin_make必须有src生成devel和build

    安装虚拟机开启intel vt 创建工作空间 first ws src catkin make在ws下生成devel和build 创建package 在src下添加package catkin create pkg hello ros ro
  • Pyhon : 爬虫Requests高级用法--证书

    客户端证书 你也可以指定一个本地证书用作客户端证书 xff0c 可以是单个文件 xff08 包含密钥和证书 xff09 或一个包含两个文件路径的元组 xff1a requests get https kennethreitz org cer
  • 【px4】运行mavsdk中的offboard example

    运行MAVSDK中的offboard例子时无人机不执行 想控制无人机前后左右移动 xff0c 在按照官方教程实现offboard 插件的时候 发现用action插件能正常起飞和降落 但是一旦执行到offboard的插件代码的时候就会自动降落
  • MDF does not reside in a read-only database or filegroup

    错误信息 The file 34 MDF 34 is compressed but does not reside in a read only database or filegroup The file must be decompre
  • Python复习笔记4——文件和目录操作

    一 文件读写 1 1 读文件 xff08 1 xff09 打开文件 使用Python内置的open 函数 xff0c 传入文件名和标示符 xff0c 打开一个文件对象 xff1a span class token operator gt g
  • Python复习笔记5——常用模块

    一 内建模块 1 1 datetime日期时间 xff08 1 xff09 导入模块 span class token keyword from span datetime span class token keyword import s
  • COLMAP+OpenMVS实现物体三维重建mesh模型

    一 环境准备 1 COLMAP 进入COLMAP官网 xff0c 打开下载页面 xff0c 下载COLMAP程序 2 OpenMVS OpenMVS可以自己从源码下载进行编译 如果觉得编译openmvs可能要费点时间 xff0c 那也可以直
  • 解决ubuntu火狐无法上网问题

    之前安装Ubuntu时是可以上网的 xff0c 呆了一个月没怎么用突然不能搜索了 xff0c 记录一下 xff0c 已解决 只需一条命令 打开终端 xff0c 输入 sudo apt get install firefox 问题解决啦 xf
  • C语言基本数据类型int, short int, long int, long long int, unsigned int, signed int等解析

    一 普通int类型 int类型是有符号整型 xff0c 即int类型的值必须是整数 xff0c 可以是正整数 xff0c 负整数 xff0c 零 int类型取值范围因计算机系统而异 早起的16位IBM PC兼容机使用16位来存储一个int值
  • Docker容器内更新apt-get 国内加速

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