使用代理获取镜像

由于国内网络受限,去到 Docker Hub 等获取镜像都会非常缓慢(甚至失败),如果有梯子,可以通过代理获取,此处使用 Clash 作为代理组件。

Docker 配置代理

在节点上准备 Clash 配置文件:

1
2
# 将梯子的 .yaml 配置文件放在此处
mkdir /root/clash

启动 Clash 容器:

1
docker run -d --restart=unless-stopped --name clash -v /root/clash/xxx.yaml:/root/.config/clash/config.yaml:ro -p 9090:9090 -p 7890:7890 -p 7891:7891 harbor.warnerchen.com/dreamacro/clash:v1.18.0

验证是否可用:

1
curl -x http://localhost:7890 https://www.google.com -I

创建 systemd 配置文件:

1
2
3
4
5
6
cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
Environment="NO_PROXY=localhost,127.0.0.0/8,harbor.warnerchen.com,registry.rancher.com,registry.rancher.cn,registry.cn-hangzhou.aliyuncs.com"
EOF

重启 Docker:

1
2
3
systemctl daemon-reload
systemctl show --property Environment docker
systemctl restart docker

验证是否可用:

1
docker pull nginx:mainline
Author

Warner Chen

Posted on

2025-02-24

Updated on

2025-02-27

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.