配置http代理拉取官方仓库镜像
参考文档:https://docs.docker.com/engine/daemon/proxy/
# 将http代理配置到shell环境变量 export http_proxy=http://192.168.6.88:10810 export HTTP_PROXY=http://192.168.6.88:10810 export HTTPS_PROXY=http://192.168.6.88:10810 export https_proxy=http://192.168.6.88:10810 # 通过拉取镜像发现docker并不会使用这个代理,重启docker服务也并不会加载代理的环境变量 [root@localhost ~]# docker pull nginx 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) # docker官方是3种配置方法 1、配置systemd插件(drop-in) [root@localhost ~]# mkdir -p /etc/systemd/system/docker.service.d [root@localhost ~]# vi /etc/systemd/system/docker.service.d/http-proxy.conf [Service] Environment="HTTP_PROXY=http://192.168.6.88:10810" Environment="HTTPS_PROXY=http://192.168.6.88:10810" Environment="NO_PROXY=localhost,127.0.0.1,.example.com" [root@localhost ~]# systemctl daemon-reload [root@localhost ~]# systemctl restart docker # 查看是否加载 [root@localhost ~]# systemctl show docker --property=Environment Environment=HTTP_PROXY=http://192.168.6.88:10810 HTTPS_PROXY=http://192.168.6.88:10810 NO_PROXY=localhost,127.0.0.1,.example.com 2、配置 daemon.json [root@localhost ~]# vi /etc/docker/daemon.json { "proxies": { "default": { "httpProxy": "http://192.168.6.88:10810", "httpsProxy": "http://192.168.6.88:10810", "noProxy": "localhost,127.0.0.1,.example.com" } } } [root@localhost ~]# systemctl restart docker 3、配置环境变量 Docker 守护进程在启动时,会检查以下环境变量实现代理 HTTP_PROXY http_proxy HTTPS_PROXY https_proxy NO_PROXY no_proxy 在上面的实际测试时并没有效果,推测是因为systemd管理的docker服务因为不是在同一个shell环境启动,不会继承这些变量。 [root@localhost ~]# /usr/bin/dockerd -h | grep proxy --http-proxy string HTTP proxy URL to use for outgoing traffic --https-proxy string HTTPS proxy URL to use for outgoing traffic --no-proxy string Comma-separated list of hosts or IP addresses for which the proxy is skipped 通过帮助文档来看是可以通过传递参数实现。但需要手动启动服务,就不能用systemd管理了。 export http_proxy=http://192.168.6.88:10810 export HTTP_PROXY=http://192.168.6.88:10810 export HTTPS_PROXY=http://192.168.6.88:10810 export https_proxy=http://192.168.6.88:10810 /usr/bin/dockerd 这样手动启动的docker服务才会继承代理变量并生效。 # 带账号密码的代理写法 http://user:pass@192.168.6.88:10810 至此,可以通过镜像站、自建registry加速、配置代理 3种方式实现拉取官方镜像
原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/5625.html