解决docker registry-1.docker.io 和 Git clone 龟速

docker error registry-1.docker.io

屏幕快照 2019-08-24 上午9.18.22.png

拉取镜像时报错代码如下

2882e4bbd1b5: Download complete
ERROR: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

1、找IP

命令:
dig @114.114.114.114 registry-1.docker.io

1566609797581.jpg

2、将IP写入hosts

命令:
sudo vim /etc/hosts

添加刚刚找的IP,格式
find-ip registry-1.docker.io
保存

3、重建缓存,让更改立即生效

命令:
sudo killall -HUP mDNSResponder

git clone 龟速

只需在上述步骤2中加入相应IP,再重建缓存即可。
实测:从10kb/s --> 1.5Mb/s

查IP代码(修改自Robin Wen),Python直接运行即可生成:

# -*- coding: utf-8 -*-
# vim:fenc=utf-8
import socket
import os
import sys

domains = '''github.com
gist.github.com
assets-cdn.github.com
raw.githubusercontent.com
gist.githubusercontent.com
cloud.githubusercontent.com
camo.githubusercontent.com
avatars0.githubusercontent.com
avatars1.githubusercontent.com
avatars2.githubusercontent.com
avatars3.githubusercontent.com
avatars4.githubusercontent.com
avatars5.githubusercontent.com
avatars6.githubusercontent.com
avatars7.githubusercontent.com
avatars8.githubusercontent.com'''
domains = domains.split()
def get_ip(host):
    """
    Get ip of host.
    """
    try:
        host_ip = socket.gethostbyname(host)
        return host_ip
    except:
        print("Unable to get IP of Hostname")

def main():
    f = open('github_hosts.txt','w')
    f.write("# GitHub Start\n")
    f.close()


    for host in domains:
        ip=get_ip(host)
        with open('github_hosts.txt', 'a') as result:
            result.write(ip.strip('\n') + " " + host + "\n")

    f = open('github_hosts.txt','a')
    f.write("# GitHub End\n")
    f.close()

if __name__ == "__main__":
    main()

你可能感兴趣的:(解决docker registry-1.docker.io 和 Git clone 龟速)