使用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).

 刚开始以为是镜像源问题,更改后没有效果

 
  1. # 操作系统:centos7

  2. # 编辑daemon.json文件

  3. vi /etc/docker/daemon.json

  4. {

  5. "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://registry.docker-cn.com","http://hub-mirror.c.163.com"]

  6. }

  7. # 重启docker

  8. systemctl restart docker

接下来进行以下操作,解决了上述无法下载的问题

 
  1. # 第一步:下载dig工具

  2. yum install bind-utils

  3. # 第二步:

  4. dig @114.114.114.114 registry-1.docker.io

  5. # 返回内容如下

  6. ; <<>> DiG 9.11.4-P2-RedHat-9.11.4-16.P2.el7_8.2 <<>> @114.114.114.114 registry-1.docker.io

  7. ; (1 server found)

  8. ;; global options: +cmd

  9. ;; Got answer:

  10. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45192

  11. ;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 0

  12. ;; QUESTION SECTION:

  13. ;registry-1.docker.io. IN A

  14. ;; ANSWER SECTION:

  15. registry-1.docker.io. 1 IN A 34.197.211.151

  16. registry-1.docker.io. 1 IN A 54.236.165.68

  17. registry-1.docker.io. 1 IN A 34.192.204.44

  18. registry-1.docker.io. 1 IN A 52.72.232.213

  19. registry-1.docker.io. 1 IN A 18.214.230.110

  20. registry-1.docker.io. 1 IN A 34.198.213.42

  21. registry-1.docker.io. 1 IN A 107.23.149.57

  22. registry-1.docker.io. 1 IN A 52.204.76.244

  23. ;; Query time: 5 msec

  24. ;; SERVER: 114.114.114.114#53(114.114.114.114)

  25. ;; WHEN: Fri Dec 18 20:08:55 CST 2020

  26. ;; MSG SIZE rcvd: 166

  27. # 第三步:接下来我们只需要把以下信息追加到/etc/hosts

  28. 34.197.211.151 registry-1.docker.io

  29. 54.236.165.68 registry-1.docker.io

  30. 34.192.204.44 registry-1.docker.io

  31. 52.72.232.213 registry-1.docker.io

  32. 18.214.230.110 registry-1.docker.io

  33. 34.198.213.42 registry-1.docker.io

  34. 107.23.149.57 registry-1.docker.io

  35. 52.204.76.244 registry-1.docker.io

接下来docker pull xx镜像,没有报错就可以正常拉取镜像了。

不过,可能会出现证书过期或无效的报错(一般是本地系统时间错误导致报错证书过期)

docker: Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid.

 
  1. # 安装

  2. yum install ntpdate

  3. # 同步时间

  4. ntpdate cn.pool.ntp.org

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐