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

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

 

posted on 2018-07-26 14:48  SimpleWorker  阅读(5039)  评论(0编辑  收藏  举报

导航