在中國大陸環境中配置 Docker 使用阿里云鏡像加速器,并確保通過 Clash 代理訪問 Docker Hub
我這里用的Debian12。
步驟 1:獲取阿里云鏡像加速器地址
登錄阿里云容器鏡像服務控制臺:(qinyang.wang)
-
網址:阿里云登錄 - 歡迎登錄阿里云,安全穩定的云計算服務平臺
-
在左側導航欄選擇“鏡像工具” > “鏡像加速器”(阿里云幫助中心)
-
復制你分配的鏡像加速器地址,例如:
https://<your_code>.mirror.aliyuncs.com
根據你提供的阿里云鏡像加速器地址 https://z5qjac8i.mirror.aliyuncs.com
,以下是配置 Docker 使用該加速器的詳細步驟:
步驟 2:配置 Docker 使用阿里云鏡像加速器
-
創建 Docker 配置目錄:
sudo mkdir -p /etc/systemd/system/docker.service.d
-
創建并編輯配置文件:
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF [Service] Environment="DOCKER_BUILDKIT=1" 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.1" EOF
請確保你的 Clash 代理服務正在運行,并監聽在 127.0.0.1:7890
。
-
重新加載 systemd 配置并重啟 Docker 服務:
sudo systemctl daemon-reload sudo systemctl restart docker
步驟 3:配置 Docker 使用阿里云鏡像加速器
-
創建或編輯 Docker 配置文件:
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<EOF {"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"] } EOF
-
重啟 Docker 服務:
sudo systemctl daemon-reload sudo systemctl restart docker
步驟 4:驗證配置是否生效
-
檢查 Docker 鏡像加速器配置:
docker info | grep -i "Registry Mirrors"
如果輸出中包含 https://z5qjac8i.mirror.aliyuncs.com
,說明配置成功。
-
測試拉取鏡像:
docker pull hello-world
如果配置正確,你應該能夠成功拉取鏡像。