docker代理
常用解决思路介绍
该方法是持久化的,修改后会一直生效。该方法覆盖了默认的docker.service文件。
-
为docker服务创建一个内嵌的systemd目录
$ mkdir -p /etc/systemd/system/docker.service.d
-
创建/etc/systemd/system/docker.service.d/http-proxy.conf文件,并添加HTTP_PROXY环境变量。其中[proxy-addr]和[proxy-port]分别改成实际情况的代理地址和端口:
[Service]
Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/" "HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/" -
如果还有内部的不需要使用代理来访问的Docker registries,那么还需要制定NO_PROXY环境变量:
[Service]
Environment="HTTP_PROXY=http://[proxy-addr]:[proxy-port]/" "HTTPS_PROXY=https://[proxy-addr]:[proxy-port]/" "NO_PROXY=localhost,127.0.0.1,docker-registry.somecorporation.com" -
更新配置:
$ systemctl daemon-reload
-
重启Docker服务:
$ systemctl restart docker
服务器地址
阿里云地址:容器镜像服务
参考:[Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled-CSDN博客](https://blog.csdn.net/qq_52712971/article/details/141862621?ops_request_misc={"request_id"%3A"184F8A15-A6F3-4AD1-98A6-047028FB70C5"%2C"scm"%3A"20140713.130102334..."}\&request_id=184F8A15-A6F3-4AD1-98A6-047028FB70C5\&biz_id=0\&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive\~default-1-141862621-null-null.142^v100^pc_search_result_base3\&utm_term=Error response from daemon%3A Get https%3A%2F%2Fregistry-1.docker.io%2Fv2%2F%3A net%2Fhttp%3A request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).&spm=1018.2226.3001.4187)
Error response from daemon:解决
Error response from daemon: Get "https://registry-1.docker.io/v2/": dial tcp 128.242.240.59:443: i/o timeout (Client.Timeout exceeded while awaiting headers).
在ubuntu中安装docker后运行sudo docker pull hello-world出现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)
我查看了很多网站上的解决方法,但是经过我个人的尝试发现我需要配置两个文件才可以解决这个问题
- 配置DNS
bash
sudo vim /etc/resolv.conf
- 修改docker的daemon.json文件为以下内容
sudo vim /etc/docker/daemon.json
bash
{
"max-concurrent-downloads": 10,
"max-concurrent-uploads": 5,
"default-shm-size": "1G",
"debug": true,
"experimental": false,
"registry-mirrors":[
"https://x9r52uz5.mirror.aliyuncs.com", # 要改成自己的
"https://dockerhub.icu",
"https://docker.chenby.cn",
"https://docker.1panel.live",
"https://docker.awsl9527.cn",
"https://docker.anyhub.us.kg",
"https://dhub.kubesre.xyz"
]
注意"https://x9r52uz5.mirror.aliyuncs.com",这里要改成自己的阿里云服务器,最终成功拉取镜像
最后更新配置、重启Docker服务
systemctl daemon-reload
systemctl restart docker