docker pull拉取超時的解決方案
最近docker pull鏡像的時候非常不穩定,速度慢不說還經常超時失敗
Pulling xlxdsj_swagger_ui (swaggerapi/swagger-ui:)...latest: Pulling from swaggerapi/swagger-uiba3557a56b15: Pull complete1a18b9f93d41: Pull complete38ceab6c6432: Pull complete6104f3bd82cc: Pull complete750e0e12d70c: Pull completed7c38a871210: Pull completecbd9bbb7c3b7: Pull complete3d6723371070: Pull complete5e5b2de4487f: Pull complete3c84c9c2d567: Pull complete9e7d57b00bb8: Pull complete5356d2f5be08: Pull completeDigest: sha256:2a746f15dacc2f2e381b3449544b82e6c7604567f05606d957ff5b7cf7d29a47Status: Downloaded newer image for swaggerapi/swagger-ui:latestPulling xlxdsj_swagger_editor (swaggerapi/swagger-editor:)...ERROR: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)大致的解決辦法有三個
1、修改DNS
2、修改鏡像倉庫地址
3、修改hosts
使用socks5代理
以下操作均在CentOS7,Ubuntu與之基本一致,macOS以及windos原理一致
修改DNS>>> vim /etc/resolv.confnameserver 8.8.8.8修改鏡像倉庫地址
>>> vim /etc/docker/daemon.json{ 'registry-mirrors': ['https://docker.mirrors.ustc.edu.cn', 'https://reg-mirror.qiniu.com']}>>> systemctl daemon-reload>>> systemctl restart docker修改host
# 安裝dig>>> sudo yum install bind-utils>>> dig @114.114.114.114 registry-1.docker.io; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.3 <<>> @114.114.114.114 registry-1.docker.io; (1 server found);; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18733;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 512;; QUESTION SECTION:;registry-1.docker.io. IN A;; ANSWER SECTION:registry-1.docker.io. 38 IN A 54.85.56.253registry-1.docker.io. 38 IN A 35.174.73.84registry-1.docker.io. 38 IN A 23.22.155.84registry-1.docker.io. 38 IN A 18.213.137.78registry-1.docker.io. 38 IN A 107.23.149.57registry-1.docker.io. 38 IN A 52.5.11.128registry-1.docker.io. 38 IN A 52.54.232.21registry-1.docker.io. 38 IN A 52.20.56.50;; Query time: 8 msec;; SERVER: 114.114.114.114#53(114.114.114.114);; WHEN: Tue Feb 23 09:03:18 CST 2021;; MSG SIZE rcvd: 177>>> sudo vim /etc/hosts35.174.73.84 registry-1.docker.io使用socks5代理
如果之前的方法效果都不太好再考慮使用這個
前提是已經裝好ss
>>> vim /etc/systemd/system/docker.service.d/http-proxy.conf[Service]Environment='HTTP_PROXY=socks5://127.0.0.1:1080'>>> systemctl daemon-reload>>> systemctl restart docker>>> systemctl show --property=Environment dockerEnvironment=HTTP_PROXY=socks5://127.0.0.1:1080
補充:解決docker pull鏡像報錯或者超時的方案,將拉取地址改為國內鏡像倉庫
docker默認鏡像拉取地址為國外倉庫下載速度較慢,甚至會報這種錯
Error response from daemon: Get https://docker.elastic.co/v2/: net/http: TLS handshake timeout
解決方法修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 鍵值。
然后重啟docker就可以了
{ 'registry-mirrors': ['https://registry.docker-cn.com']}
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。如有錯誤或未考慮完全的地方,望不吝賜教。
相關文章:
