如何解决Docker网络请求问题:https://registry-1.docker.io/v2/ request canceled报错

报错

docker pull nginx
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

 方法一:给docker配置一个代理

Docker 代理

在执行docker pull时,是由守护进程dockerd来执行。因此,代理需要配在dockerd的环境中。而这个环境,则是受systemd所管控,因此实际是systemd的配置。

sudo mkdir -p /etc/systemd/system/docker.service.d
sudo touch /etc/systemd/system/docker.service.d/proxy.conf

在这个proxy.conf文件(可以是任意*.conf的形式)中,添加以下内容:

[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
 【注】HTTP_PROXY 用于代理访问 http 请求,HTTPS_PROXY 用于代理访问 https 请求,如果想某个 IP域名不走代理则配置到 NO_PROXY中。
范例:
sudo mkdir -p /etc/systemd/system/docker.service.d

cat > /etc/systemd/system/docker.service.d/proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://10.0.0.1:7890/"
Environment="HTTPS_PROXY=http://10.0.0.1:7890/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
EOF

systemctl daemon-reload ;systemctl restrat docker

你可能感兴趣的:(运维小知识秘籍,docker,容器,云计算,运维,安全)