🏓我們有時候雖然配置了Docker國內鏡像源,但是還是會繞過去請求官方鏡像源(docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded),現在我們就來解決一下,這是其中的一個解決方案,僅供參考:
1、先診斷一下網絡有沒有問題,一般是不會有問題的
ping -c 3 8.8.8.8 # 測試基本互聯網連接nslookup registry-1.docker.io # 測試Docker Hub域名解析curl -I --connect-timeout 10 https://registry-1.docker.io/v2/ # HTTP連接測試
2、分析現有的Docker配置
cat /etc/docker/daemon.json
這個鏡像源是免費的,也比較穩定,大家可以試試:https://docker.xuanyuan.me/
🧨我們在daemon.json中做了如下配置:
{"registry-mirrors": ["https://registry.cn-hangzhou.aliyuncs.com","https://mirror.ccs.tencentyun.com","https://ccr.ccs.tencentyun.com"],"dns": ["8.8.8.8", "114.114.114.114"], # 添加DNS配置# 優化并發設置"max-concurrent-downloads": 10,"max-concurrent-uploads": 5
}
3、測試驗證
# 加載配置文件
sudo systemctl daemon-reload
# 重啟docker
sudo systemctl restart docker# 驗證配置生效
docker info | grep -A 5 "Registry Mirrors"# 最終功能測試
timeout 30 docker run hello-world
?到這里如果有以下輸出,就表示更換鏡像源已經完成了!
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.3. The Docker daemon created a new container from that image which runs theexecutable that produces the output you are currently reading.4. The Docker daemon streamed that output to the Docker client, which sent itto your terminal.To try something more ambitious, you can run an Ubuntu container with:$ docker run -it ubuntu bashShare images, automate workflows, and more with a free Docker ID:https://cloud.docker.com/For more examples and ideas, visit:https://docs.docker.com/engine/userguide/