docker设置代理服务器,解决pull命令:Error response from daemon: Get https://registry-1.docker.io/v2…

2022年6月7日08:49:54

当虚拟机无法连接访问到外网https://registry-1.docker.io/v2,执行docker pull命令会抛出异常,如下:

[root@localhost default]# docker pull debian
Using default tag: latest
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)

通过设置代理可以解决:

  • 创建http-proxy.conf文件:

    $ mkdir -p /etc/systemd/system/docker.service.d
    $ vim /etc/systemd/system/docker.service.d/http-proxy.conf
  添加如下内容:
    [Service]
    Environment="HTTP_PROXY=http://<allowed_proxy_ipv4_address>:<proxy_port_num>/"
    [Service]
    Environment="HTTPS_PROXY=https://<allowed_proxy_ipv4_address>:<proxy_port_num>/"

  • 执行reload命令:  $ sudo systemctl daemon-reload
  • 重启docker:  $ sudo systemctl restart docker
  • 查看环境变量值: $ systemctl show --property=Environment docker

再次执行:

[root@localhost docker.service.d]# docker pull debian
Using default tag: latest
latest: Pulling from library/debian
55cbf04beb70: Pull complete
Digest: sha256:f1f61086ea01a72b30c7287adee8c929e569853de03b7c462a8ac75e0d0224c4
Status: Downloaded newer image for debian:latest

转载于:https://www.cnblogs.com/onetwothree/p/9371752.html

  • 作者:weixin_34233679
  • 原文链接:https://blog.csdn.net/weixin_34233679/article/details/93281215
    更新时间:2022年6月7日08:49:54 ,共 1057 字。