执行docker run命令时报错Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
一.解决办法: 修改host
二.步骤如下
2.1 安装dig工具
sudo apt-get install dnsutils -y (ubuntu下的安装方法)
2.2 找到registry-1.docker.io对应的ip地址
jello$ dig @8.8.8.8 registry-1.docker.io
; <<>> DiG 8.8 hello <<>> @8.8.8.8 registry-1.docker.io
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6620
;; 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. 40 IN A 34.201.236.93
registry-1.docker.io. 40 IN A 34.206.236.31
registry-1.docker.io. 40 IN A 34.233.151.211
registry-1.docker.io. 40 IN A 34.228.211.243
registry-1.docker.io. 40 IN A 52.22.67.152
registry-1.docker.io. 40 IN A 34.201.196.144
registry-1.docker.io. 40 IN A 52.22.201.61
registry-1.docker.io. 40 IN A 34.232.31.24
;; Query time: 162 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Mon August 8 8:8:8 CST 2018
;; MSG SIZE rcvd: 177
2.3 修改hosts表
echo 34.233.151.211 registry-1.docker.io > /etc/hosts
补充:
方法二:添加dns 8.8.8.8
a 将nameserver 8.8.8.8写入/etc/resolvconf/resolv.conf.d/head文件中
sudo vi /etc/resolvconf/resolv.conf.d/head
b 更新dns
sudo resolvconf -u
方法三:修改镜像源
a sudo vi /etc/docker/daemon.json
写入以下内容:
{ "registry-mirrors":["https://docker.mirrors.ustc.edu.cn"] }
b 重新加载docker的配置文件
sudo systemctl daemon-reload
c 重启docker
sudo systemctl restart docker
方法四: 设置代理(需要设置代理才能访问外网)
a ubuntu上设置代理(添加代理配置到对应配置文件)
$ cat /etc/systemd/system/docker.service.d/http-proxy.conf
注意: 如果用户名或密码中有特殊符号,请使用%+ascii来替换,比如说用户名中有#字符,那么使用%23来代替#