背景:
由于本地内网服务器的internet是受限制的(需要配置远程代理上网,不能直接上网)。因此,在使用docker连接docker hub的时候,就会出错。

docker pull nginx(拉取dockerhub镜像)

问题一:
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while aw

 

解决方法:设置Http和Https代理
mkdir -p /etc/systemd/system/docker.service.d
vim /etc/systemd/system/docker.service.d/proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.1.9:1080"
Environment="HTTPS_PROXY=https://192.168.1.9:1080"

注:
HTTP_PROXY 和 HTTPS_PROXY 将它的值对应到您设置的代理服务地址和端口
Environment="HTTP_PROXY=http://proxy.example.com:80"
Environment="HTTPS_PROXY=https://proxy.example.com:443"


刷新更改并重新启动Docker
systemctl daemon-reload
systemctl restart docker

参考文档:https://docs.docker.com/config/daemon/systemd/

## https://www.cnblogs.com/liucx/

 

2.设置代理后,仍然无法拉取镜像

问题二:
Docker pull:TLS握手超时

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)

 

但是使用curl TLS可以正常工作
curl https://registry-1.docker.io/v2/
{"errors":[{"code":"UNAUTHORIZED","message":"authentication required","detail":null}]}

在网络上搜索了半天,基本是设置docker加速器或者修改MTU大小

## https://www.cnblogs.com/liucx/

 

最后解决方法:
将https代理的地址 改成 http//网址
vim /etc/systemd/system/docker.service.d/proxy.conf
Environment="HTTP_PROXY=http://192.168.1.9:1080"
Environment="HTTPS_PROXY=http://192.168.1.9:1080"

 

刷新更改并重新启动Docker
systemctl daemon-reload
systemctl restart docker

现在一切正常,希望能帮到您,帮忙点个赞哈

内容来源于网络如有侵权请私信删除