Docker ubuntn 使用apt-get update报错

在docker 容器中执行apt-get update有时候会报错,当然造成错误的原因有很多情况,具体情况具体分析,

APT Hash sum mismatch错误的常见解决方法总结这篇博客写的不错,在此感谢博主提供的思路。

以下是本人解决docker容器中执行apt-get update报错的解决办法(踩了好多坑,血淋淋的阿,终于好用了。):

root@33c5b2ae7edc:/# apt-get update
Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
Temporary failure resolving 'security.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
Temporary failure resolving 'archive.ubuntu.com'
Err:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease
Temporary failure resolving 'archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-backports/InRelease Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/xenial-security/InRelease Temporary failure resolving 'security.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
<1> 首先配置docker容器的DNS

cat /etc/resolv.conf       该命令查看容器和宿主机的DNS设置,容器和宿主机的DNS设置应该一致。

docker DNS的设置可以通过启动容器时添加参数  --dns  8.8.8.8  来设置(本次有效)

或者通过 /etc/default/docker的DNS参数来进行永久设置,然后重启DOCKER生效,

     export http_proxy="http://10.1.9.100:808/"
   DOCKER_OPTS="--dns 210.83.210.155 --dns 127.0.1.1"

 

sudo service docker restart

<2> 查看容器 /etc/apt/目录中是否有apt.conf文件,该文件配置了代理:

Acquire::http::proxy "http://10.1.9.100:8080/";
Acquire::ftp::proxy "ftp://10.1.9.100:8080/";
Acquire::https::proxy "https://10.1.9.100:8080/";
如果没有该文件,可以将宿主机中的apt.conf文件拷贝到容器对应目录中。

<3>对代理服务器进行设置:

还有些开发者遇到的问题,是因为公司的Proxy的设置。
如果读者朋友使用了Proxy,那么可以尝试,在容器的 /etc/apt/apt.conf.d/ 目录下创建一个名称为99fixbadproxy 的文件

$ sudo gedit /etc/apt/apt.conf.d/99fixbadproxy
把以下文本复制到上述文件中,然后保存退出:

Acquire::http::Pipeline-Depth 0;
Acquire::http::No-Cache true;
Acquire::BrokenProxy true;
<4> 清cache缓存:

$ sudo apt-get clean
$ sudo apt-get update --fix-missing
<5> 可以更改APT源,网上有挺多的国内源,可以搜索更改办法。

posted on   剩余价值  阅读(3603)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示