docker局域网服务器设置代理服务器拉取外网镜像【转】

当虚拟机无法连接访问到外网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
添加如下内容:
Environment="HTTP_PROXY=http://(host_name):(port_number)/" "HTTPS_PROXY=http://(host_name):(port_number)/"

如果设置格式如下会有 Get https://registry-1.docker.io/v2/: proxyconnect tcp: tls: first record does not look like a TLS 报错

[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

 

转自

docker设置代理服务器,解决pull命令:Error response from daemon: Get https://registry-1.docker.io/v2 - SimpleWorker - 博客园
https://www.cnblogs.com/onetwothree/p/9371752.html

Error response from daemon: Get http s://registry-1.docker.io/v2/: proxyconnect tcp: tls: first record does not look like a TLS handshake - Stack Overflow
https://stackoverflow.com/questions/50392780/error-response-from-daemon-get-http-s-registry-1-docker-io-v2-proxyconnect/50409451

 

posted @ 2021-02-20 16:36  paul_hch  阅读(1493)  评论(0编辑  收藏  举报