docker拉取rabbitmq镜像时报Client.Timeout exceeded while awaiting header错误处理办法
docker拉取镜像时报:Error response from daemon: Get “https://registry-1.docker.io/v2/”: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)错误解决办法!
说明
原本是要拉取rabbitmq的镜像,但是一连试了好几种方式好像都不行,尝试查找验证各种方案,修改hosts文件等都不行,也尝试使用修改过daemon.json文件,但最终还是报这个错,就在最后发现了一位大佬的笔记,抱着试试的心态尝试了一下大佬的解决方案,没有想到最后成功解决了,感谢这位大佬,这里贴一下大佬的笔记:
https://blog.csdn.net/qq_28809683/article/details/143110434
1、docker版本说明
Docker version 26.1.4, build 5650f9b
2、错误说明
[root@VM-20-6-centos docker]# docker pull rabbitmq:3.9.13-management
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
3、解决办法
3.1、进入/etc/docker目录下,修改daemon.json文件
特别说明,一般安装docker的时候如果配置了这个文件,这个文件是会存在的,如果不存在也没有关系,直接新建一个daemon.json文件也是可以的,但是记得给权限就行,
[root@VM-20-6-centos docker]# vi daemon.json
然后将以下内容粘贴进daemon.json文件中,保存退出。
{
"registry-mirrors": ["https://docker.1panelproxy.com"]
}
重点是这个镜像仓库:https://docker.1panelproxy.com,因此里面只需要保存这个镜像仓库地址即可
以下是我的daemon.json,仅供参考!
{
"registry-mirrors": [
"https://docker.1panelproxy.com",
"https://2m11665s.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"https://dockerhub.azk8s.cn",
"https://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com",
"https://k8s.gcr.io",
"https://github-releases.githubusercontent.com",
"https://ustc-edu-cn.mirror.aliyuncs.com"
],
"insecure-registries": [
"registry.me:5000",
"http://docker.mirrors.ustc.edu.cn",
"https://k8s.gcr.io",
"https://github-releases.githubusercontent.com",
"https://registry-1.docker.io",
"decs.com"
],
"exec-opts": [
"native.cgroupdriver=systemd"
]
}
3.2、修改保存完daemon.json文件后,重启一下docker,执行以下两条命令即可
[root@VM-20-6-centos docker]# systemctl daemon-reload
[root@VM-20-6-centos docker]# systemctl restart docker
最后验证一下是否可以拉取想要的镜像
[root@VM-20-6-centos docker]# docker pull rabbitmq:3.9.13-management
3.9.13-management: Pulling from library/rabbitmq
4d32b49e2995: Pull complete
2108a18330ce: Pull complete
5c6af9d52173: Pull complete
0f88690b6c7c: Pull complete
9531e199a7d9: Pull complete
efaba55aede6: Pull complete
41502a4f43bc: Pull complete
11b60d9df2ff: Pull complete
ac0763dc13e5: Pull complete
73e951ed9965: Pull complete
Digest: sha256:981f32e8962311fb94e1cc11b868b2790f23a49a003310c6b0fdfcd4b8f6fbe6
Status: Downloaded newer image for rabbitmq:3.9.13-management
docker.io/library/rabbitmq:3.9.13-management
发现可以正常拉取
3.3、如果是需要在安装时指定,可执行以下命令
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://docker.1panelproxy.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
效果是和上面一样的
4、写在最后
4.1、在排查这个错误的过程中,发现了几个好玩的命令的,记录一下
journalctl:查看docker.service的运行过程及日志信息
[root@VM-20-6-centos docker]# journalctl -u docker.service
-- Logs begin at Sun 2024-11-03 11:03:44 CST, end at Sun 2024-11-03 14:18:01 CST. --
Nov 03 13:44:47 VM-20-6-centos systemd[1]: Starting Docker Application Container Engine...
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.111023379+08:00" level=info msg="Starting up"
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.176372586+08:00" level=info msg="Loading containers: start."
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.323561593+08:00" level=info msg="Loading containers: done."
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.340946554+08:00" level=info msg="Docker daemon" commit=de5c9cf containerd-snapshotter=false storage-driver=overlay2 versio
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.341052003+08:00" level=info msg="Daemon has completed initialization"
Nov 03 13:44:47 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:44:47.384724973+08:00" level=info msg="API listen on /run/docker.sock"
Nov 03 13:44:47 VM-20-6-centos systemd[1]: Started Docker Application Container Engine.
Nov 03 13:56:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:56:10.743537278+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": net/http: request
Nov 03 13:56:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:56:10.743600242+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 13:56:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:56:10.748356105+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 13:59:36 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:59:36.278741993+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": net/http: request
Nov 03 13:59:36 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:59:36.278794723+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 13:59:36 VM-20-6-centos dockerd[3651]: time="2024-11-03T13:59:36.280970330+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:02:15 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:02:15.341624331+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": net/http: request
Nov 03 14:02:15 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:02:15.341687140+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 14:02:15 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:02:15.343735103+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:04:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:04:10.120222654+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": context deadline
Nov 03 14:04:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:04:10.120276342+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 14:04:10 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:04:10.122316401+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:05:06 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:05:06.583359672+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": net/http: request
Nov 03 14:05:06 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:05:06.583461822+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 14:05:06 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:05:06.585528695+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:09:52 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:09:52.575316988+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": dial tcp 162.220.
Nov 03 14:09:52 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:09:52.575369473+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 14:09:52 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:09:52.577153224+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:10:17 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:10:17.460367615+08:00" level=warning msg="Error getting v2 registry: Get "https://registry-1.docker.io/v2/": net/http: request
Nov 03 14:10:17 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:10:17.460436573+08:00" level=info msg="Attempting next endpoint for pull after error: Get "https://registry-1.docker.io/v2/":
Nov 03 14:10:17 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:10:17.462493941+08:00" level=error msg="Handler for POST /v1.45/images/create returned error: Get "https://registry-1.docker.io
Nov 03 14:15:11 VM-20-6-centos systemd[1]: Stopping Docker Application Container Engine...
Nov 03 14:15:11 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:15:11.480075709+08:00" level=info msg="Processing signal 'terminated'"
Nov 03 14:15:11 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:15:11.481445523+08:00" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd nam
Nov 03 14:15:11 VM-20-6-centos dockerd[3651]: time="2024-11-03T14:15:11.482076140+08:00" level=info msg="Daemon shutdown complete"
Nov 03 14:15:11 VM-20-6-centos systemd[1]: Stopped Docker Application Container Engine.
Nov 03 14:15:11 VM-20-6-centos systemd[1]: Starting Docker Application Container Engine...
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.544793571+08:00" level=info msg="Starting up"
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.545593459+08:00" level=warning msg="insecure registry http://docker.mirrors.ustc.edu.cn should not contain 'http://' and
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.545635510+08:00" level=warning msg="insecure registry https://k8s.gcr.io should not contain 'https://' and 'https://' has
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.545650486+08:00" level=warning msg="insecure registry https://github-releases.githubusercontent.com should not contain 'h
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.545666860+08:00" level=warning msg="insecure registry https://registry-1.docker.io should not contain 'https://' and 'htt
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.581613144+08:00" level=info msg="[graphdriver] using prior storage driver: overlay2"
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.581835106+08:00" level=info msg="Loading containers: start."
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.661587858+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --b
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.694569327+08:00" level=info msg="Loading containers: done."
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.710071576+08:00" level=warning msg="WARNING: bridge-nf-call-iptables is disabled"
Nov 03 14:15:11 VM-20-6-centos dockerd[21992]: time="2024-11-03T14:15:11.710097978+08:00" level=warning msg="WARNING: bridge-nf-call-ip6tables is disabled"
dig
[root@VM-20-6-centos docker]# dig @114.114.114.114 registry-1.docker.io
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.16 <<>> @114.114.114.114 registry-1.docker.io
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21874
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, 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. 127 IN A 69.63.186.31
;; Query time: 30 msec
;; SERVER: 114.114.114.114#53(114.114.114.114)
;; WHEN: Sun Nov 03 14:29:07 CST 2024
;; MSG SIZE rcvd: 65