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
### Docker镜像时因网络超时导致的错误解决方案 当执行 `docker pull` 命令时遇到 `Client.Timeout exceeded while awaiting headers` 错误,通常是因为网络连接不稳定或者Docker守护进程配置不当引起的。以下是几种常见的解决方法: #### 方法一:设置国内镜像源加速 可以通过修改Docker的配置文件来添加国内镜像源地址,从而减少请求延迟并提高下载速度。 编辑或创建 `/etc/docker/daemon.json` 文件(Linux),Windows 用户可以在 Docker Desktop 的设置界面完成相同操作: ```json { "registry-mirrors": [ "https://docker.m.daocloud.io", "https://hub-mirror.c.163.com" ] } ``` 保存后重启Docker服务以使更改生效[^4]。 #### 方法二:调整Docker客户端超时时间 如果默认的超时时间不足以满足当前环境下的需求,则可以尝试增加超时阈值。通过命令行参数指定更长的时间限制来进行单次pull操作: ```bash timeout 600s docker pull rabbitmq:latest ``` 另外也可以全局范围内永久性延长此值,在启动容器之前先运行下面这条指令设定新的最大允许等待秒数[^2]: ```bash export DOCKER_CLIENT_TIMEOUT=180 export COMPOSE_HTTP_TIMEOUT=180 ``` #### 方法三:清理缓存与重置存储空间 有时旧数据残留可能会干扰新版本获过程中的正常通信流程。因此有必要定期清除不必要的层以及释放磁盘占用情况。 ```bash docker system prune -a --volumes ``` 上述命令会删除所有停止状态下的容器实例连同其关联卷一起移除;同时还会清空未被任何标签引用过的悬空映象及其历史记录副本[^3]。 #### 方法四:切换到其他可用节点 假如以上措施均未能奏效的话,那么可能是目标主机本身存在问题或者是区域性封锁所致。此时建议更换至备用站点继续尝试访问资源。 例如替换官方仓库链接为阿里云企业版私有库形式调用: ```bash docker login registry.cn-hangzhou.aliyuncs.com docker pull registry.cn-hangzhou.aliyuncs.com/library/rabbitmq:management ``` --- ### 总结 综上所述,针对此类问题可以从优化本地配置出发逐步排查直至最终定位根本原因所在。无论是采用何种手段都需确保网络安全策略许可范围之内合法合规地实施相应动作。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值