Featured image of post Docker、Containerd使用代理拉取镜像

Docker、Containerd使用代理拉取镜像

如何在Docker和Containerd中使用代理来拉取镜像,以帮助开发运维更高效地管理和部署容器化应用。

  • Docker
sudo mkdir -p /etc/systemd/system/docker.service.d

sudo tee /etc/systemd/system/docker.service.d/proxy.conf <<-'EOF'

[Service]

Environment="HTTP_PROXY=http://proxy.example.com:8080/"

Environment="HTTPS_PROXY=http://proxy.example.com:8080/"
# dockerd 绕过代理服务器直连
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

EOF

# 重新加载配置文件,重启 dockerd
sudo systemctl daemon-reload

sudo systemctl restart docker

Containerd

新增 /etc/systemd/system/containerd.service.d/http-proxy.conf 配置文件

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"
EOF
systemctl daemon-reload
systemctl restart containerd
Licensed under CC BY-NC-SA 4.0