服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - docker pull拉取超时的解决方案

docker pull拉取超时的解决方案

2021-06-18 17:34micromicrofat 服务器知识

这篇文章主要介绍了docker pull拉取超时的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

最近docker pull镜像的时候非常不稳定,速度慢不说还经常超时失败

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Pulling xlxdsj_swagger_ui (swaggerapi/swagger-ui:)...
latest: Pulling from swaggerapi/swagger-ui
ba3557a56b15: Pull complete
1a18b9f93d41: Pull complete
38ceab6c6432: Pull complete
6104f3bd82cc: Pull complete
750e0e12d70c: Pull complete
d7c38a871210: Pull complete
cbd9bbb7c3b7: Pull complete
3d6723371070: Pull complete
5e5b2de4487f: Pull complete
3c84c9c2d567: Pull complete
9e7d57b00bb8: Pull complete
5356d2f5be08: Pull complete
Digest: sha256:2a746f15dacc2f2e381b3449544b82e6c7604567f05606d957ff5b7cf7d29a47
Status: Downloaded newer image for swaggerapi/swagger-ui:latest
Pulling 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

?
1
2
>>> vim /etc/resolv.conf
nameserver 8.8.8.8

修改镜像仓库地址

?
1
2
3
4
5
6
>>> 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

?
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
# 安装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.253
registry-1.docker.io. 38 IN A 35.174.73.84
registry-1.docker.io. 38 IN A 23.22.155.84
registry-1.docker.io. 38 IN A 18.213.137.78
registry-1.docker.io. 38 IN A 107.23.149.57
registry-1.docker.io. 38 IN A 52.5.11.128
registry-1.docker.io. 38 IN A 52.54.232.21
registry-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/hosts
35.174.73.84 registry-1.docker.io

使用socks5代理

如果之前的方法效果都不太好再考虑使用这个

前提是已经装好ss

?
1
2
3
4
5
6
7
>>> 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 docker
Environment=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就可以了

?
1
2
3
{
 "registry-mirrors": ["https://registry.docker-cn.com"]
}

docker pull拉取超时的解决方案

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。如有错误或未考虑完全的地方,望不吝赐教。

原文链接:https://blog.csdn.net/MacwinWin/article/details/113967667

延伸 · 阅读

精彩推荐