因为众所周知的原因,现在docker、containerd拉取镜像经常拉取不到。下面来配置下containerd怎么使用本地代理来拉取镜像。

通过 systemd 设置

如果你的 docker daemon 是通过 systemd 管理的,那么你可以通过设置 containerd.service 服务的环境变量来设置代理。
执行命令查看 containerd.service 信息,得知配置文件位置 /etc/systemd/system/containerd.service

~$ systemctl status containerd
● containerd.service - containerd container runtime
Loaded: loaded (/etc/systemd/system/containerd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2024-08-20 15:03:40 CST; 1h 24min ago
Docs: https://containerd.io
Process: 1098607 ExecStartPre=/sbin/modprobe overlay (code=exited, status=0/SUCCESS)
Main PID: 1098609 (containerd)
Tasks: 32
Memory: 85.9M
CGroup: /system.slice/containerd.service
└─1098609 /usr/local/bin/containerd

/etc/systemd/system/containerd.service 的 [Service] 模块添加:

Environment=HTTP_PROXY=http://proxyAddress:port
Environment=HTTPS_PROXY=http://proxyAddress:port
Environment=NO_PROXY=localhost,127.0.0.1

重新加载配置文件并重启服务:

systemctl daemon-reload
systemctl restart containerd