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源,網上有挺多的國內源,能夠搜索更改辦法。

相關文章
相關標籤/搜索