Docker ubuntn 使用apt-get update报错

在docker 容器中执行apt-get update有时候会报错,固然形成错误的缘由有不少状况,具体状况具体分析,docker

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

如下是本人解决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设置应该一致。fetch

docker DNS的设置能够经过启动容器时添加参数  --dns  8.8.8.8  来设置(本次有效)ui

或者经过 /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"rest

 

sudo service docker restartdns

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

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

相关文章
相关标签/搜索