当前位置: 代码网 > 服务器>服务器>云虚拟主机 > 告别Docker请求超时之一步步排查与详细解决方案

告别Docker请求超时之一步步排查与详细解决方案

2025年02月13日 云虚拟主机 我要评论
docker运行系统系统:ubuntu问题现象在ubuntu系统上面,安装完docker后,尝试运行docker run hello-world来测试docker安装是否成功的时候,报错,报错信息如下

docker运行系统

系统:ubuntu

问题现象

在ubuntu系统上面,安装完docker后,尝试运行 docker run hello-world 来测试docker安装是否成功的时候,报错,报错信息如下:

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).
see 'docker run --help'.

解决方案

对于这种连接超时的问题,网上有很多的解决方案,我也根据网上的解决方案尝试了,但是有些处理方案不起作用,也在下面处理方案列出,希望对你们有所帮助。

1. 修改docker镜像源 (本地修改后不行)

使用命令 sudo vim /etc/docker/daemon.json (若文件不存在,会自动创建一个新的daemon.json文件),替换文件中的镜像源信息

{
    "registry-mirrors": ["https://docker.registry.cyou",
      "https://docker-cf.registry.cyou",
      "https://dockercf.jsdelivr.fyi",
      "https://docker.jsdelivr.fyi",
      "https://dockertest.jsdelivr.fyi",
      "https://mirror.aliyuncs.com",
      "https://dockerproxy.com",
      "https://mirror.baidubce.com",
      "https://docker.m.daocloud.io",
      "https://docker.nju.edu.cn",
      "https://docker.mirrors.sjtug.sjtu.edu.cn",
      "https://docker.mirrors.ustc.edu.cn",
      "https://mirror.iscas.ac.cn"]
  }

修改后需重新docker服务

sudo systemctl daemon-reload
sudo systemctl restart docker

检查是否生效:查看docker系统信息 docker info,查看 registry mirror 中刚配置的内容地址。

2. 修改dns服务配置

  • 查看dns服务配置,/etc/resolv.conf
cat /etc/resolv.conf
  • 查看nameserver后面ip地址信息,或者显示的ip地址有问题,可以尝试修改该文件。
nameserver 114.114.114.114
nameserver 8.8.8.8

3. 获取可用的镜像源(成功拉取镜像源)

以上方法都不起作用后,找了很久,终于找到一个可用的镜像源

https://docker.rainbond.cc/

将上述信息添加到damon.json文件中,然后重启服务,docker run hello-world 尝试拉取镜像,成功。

unable to find image 'hello-world:latest' locally
latest: pulling from library/hello-world
c1ec31eb5944: pull complete 
digest: sha256:d211f485f2dd1dee407a80973c8f129f00d54604d2c90732e8e320e5038a0348
status: downloaded newer image for hello-world:latest

hello from docker!
this message shows that your installation appears to be working correctly.

to generate this message, docker took the following steps:
 1. the docker client contacted the docker daemon.
 2. the docker daemon pulled the "hello-world" image from the docker hub.
    (amd64)
 3. the docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. the docker daemon streamed that output to the docker client, which sent it
    to your terminal.

to try something more ambitious, you can run an ubuntu container with:
 $ docker run -it ubuntu bash

share images, automate workflows, and more with a free docker id:
 https://hub.docker.com/

for more examples and ideas, visit:
 https://docs.docker.com/get-started/

总结:

在这篇博客中,提供了一系列处理docker拉取镜像超时的实用的解决方案。我们首先分析了网络连接问题、dns配置错误以及代理设置等可能导致该错误的因素。接着,我们详细讲解了如何通过调整docker配置文件、修改dns选项以及检查系统代理设置等方法来解决这一问题。
通过这些步骤,相信你已经能够有效地解决“client.timeout exceeded while awaiting headers”错误,让你的docker容器顺利运行。掌握这些技巧,不仅能帮助你处理当前的问题,也为你在未来面对类似挑战时提供了有力的工具。

希望这篇教程对你有所帮助,助你在docker的使用过程中更加得心应手。谢谢阅读,期待你的反馈!

到此这篇关于docker请求超时排查与详细解决方案的文章就介绍到这了,更多相关docker请求超时排查与解决内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com