博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Docker ubuntn 使用apt-get update报错
阅读量:4082 次
发布时间:2019-05-25

本文共 2220 字,大约阅读时间需要 7 分钟。

转载自:

在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源,网上有挺多的国内源,可以搜索更改办法。

你可能感兴趣的文章
React Native开源项目GCore
查看>>
React Native CodePush实践小结
查看>>
React Native 性能优化之可取消的异步操作
查看>>
React Native启动白屏问题
查看>>
React Native 在原生项目中集成之坑点总结
查看>>
React Native for Android 发布独立的安装包
查看>>
React Native应用部署/热更新-CodePush最新集成总结(新)
查看>>
react-native-wechat
查看>>
基于云信的react-native聊天系统
查看>>
Vue2.0全家桶仿腾讯体育APP
查看>>
Android项目集成ReactNativeMac版
查看>>
React Native 应用在键盘弹出时优雅地响应
查看>>
音乐客户端的计时 App
查看>>
用 Vue 撸一个微博客户端
查看>>
初识 weex(前端视角)
查看>>
网易云音乐移动客户端Vue.js
查看>>
JavaScript异步函数
查看>>
ES7 await/async
查看>>
ES7的Async/Await
查看>>
iOS 开发调用相机以及获取相册照片功能
查看>>