docker代理配置相关

时间:2024-10-23 10:01:40

docker代理

常用解决思路介绍

该方法是持久化的,修改后会一直生效。该方法覆盖了默认的docker.service文件。

1. 为docker服务创建一个内嵌的systemd目录

$ mkdir -p /etc/systemd/system/docker.service.d

2. 创建/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]/"

3. 如果还有内部的不需要使用代理来访问的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"

4. 更新配置:

$ systemctl daemon-reload

5. 重启Docker服务:

$ systemctl restart docker

https://blog.****.net/m0_61067876/article/details/139846707?ops_request_misc=%7B%22request%5Fid%22%3A%226E26C72E-B719-4399-960D-71EA1BAD4CC8%22%2C%22scm%22%3A%2220140713.130102334…%22%7D&request_id=6E26C72E-B719-4399-960D-71EA1BAD4CC8&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_click~default-2-139846707-null-null.142v100pc_search_result_base3&utm_term=阿里云服务器安装docker&spm=1018.2226.3001.4187)

服务器地址

阿里云地址:容器镜像服务

参考:[Error response from daemon: Get “https://registry-1.docker.io/v2/“: net/http: request canceled-****博客](https://blog.****.net/qq_52712971/article/details/141862621?ops_request_misc=%7B%22request%5Fid%22%3A%22184F8A15-A6F3-4AD1-98A6-047028FB70C5%22%2C%22scm%22%3A%2220140713.130102334…%22%7D&request_id=184F8A15-A6F3-4AD1-98A6-047028FB70C5&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-141862621-null-null.142v100pc_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)
在这里插入图片描述
我查看了很多网站上的解决方法,但是经过我个人的尝试发现我需要配置两个文件才可以解决这个问题

  1. 配置DNS
sudo vim /etc/resolv.conf

在这里插入图片描述
2. 修改docker的daemon.json文件为以下内容
sudo vim /etc/docker/daemon.json

{
     "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