執行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

    [Service]
    Environment="HTTP_PROXY= http://USERNAME:PASSWORD@PROXYIP:PROXYPORT" (請根據自己的情況替換用戶名,密碼,代理服務器ip和代理端口)
    Environment="HTTPS_PROXY= http://USERNAME:PASSWORD@PROXYIP:PROXYPORT" (請根據自己的情況替換用戶名,密碼,代理服務器ip和代理端口)
    Environment="NO_PROXY=localhost,127.0.0.1, docker-registry.example.com,.corp" (請根據自己的情況替換)
     注意: 如果用戶名或密碼中有特殊符號,請使用%+ascii來替換,比如說用戶名中有#字符,那么使用%23來代替#
    b 使配置生效
    $ sudo systemctl daemon-reload
    $ sudo systemctl restart docker
    c 檢查代理是否生效
    $ sudo docker info | grep Proxy
    HTTP Proxy: http://xxxxx: xxxxx@PROXYIP:PORT
    HTTPS Proxy: http://xxxxx: xxxxx@PROXYIP:PORT
    No Proxy: localhost,127.0.0.1, docker-registry.example.com,.corp"


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM