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

早过忘川 提交于 2020-04-29 18:47:21

当虚拟机无法连接访问到外网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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!