在执行docker pull时,是由守护进程dockerd来执行。因此,代理需要配在dockerd的环境中。而这个环境,则是受systemd所管控,因此实际是systemd的配置。containerd也不例外。

docker版:

#设置代理
mkdir -p /etc/systemd/system/docker.service.d
touch /etc/systemd/system/docker.service.d/proxy.conf
tee /etc/systemd/system/containerd.service.d/proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:8080/"
Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"
EOF

#重新加载
systemctl daemon-reload

#查看最新配置
systemctl show --property Environment docker

#重启docker,让配置生效
systemctl restart docker

#查看代理配置
docker info | grep Proxy

 

containerd版:

#设置代理
mkdir -p /etc/systemd/system/containerd.service.d 
touch /etc/systemd/system/containerd.service.d/http-proxy.conf 
tee /etc/systemd/system/containerd.service.d/http-proxy.conf << EOF 
[Service] 
Environment="HTTP_PROXY=http://IP:Port" 
Environment="HTTPS_PROXY=http://IP:Port" 
Environment="NO_PROXY=localhost,127.0.0.1,containerd,172.25.0.0/16" 
EOF

#重新加载
systemctl daemon-reexec
systemctl daemon-reload

#重启应用
systemctl restart containerd

#验证代理是否生效
systemctl show containerd | grep -i proxy
声明:欢迎大家光临本站,学习IT运维技术,转载本站内容,请注明内容出处”来源刘国华教育“。如若本站内容侵犯了原著者的合法权益,请联系我们进行处理。