Appearance
Docker Hub 镜像拉取失败、npm 与 pip 下载超时代理配置终极方案
快速答案
实测有效配置解决开发工具超时的最佳路径:
- 1. Docker Desktop 需在 Settings -> Resources -> Proxies 中配置 HTTP/HTTPS 代理为
http://127.0.0.1:7897 - 2. npm 执行
npm config set proxy http://127.0.0.1:7897 - 3. pip 执行
pip config set global.proxy http://127.0.0.1:7897 - 4. 或者在 Clash Verge 中开启 TUN 模式直接全局透明接管。
核心结论
彻底解决 image pull failed 与 ConnectTimeoutError。一、Docker Hub 镜像拉取代理配置
自 2024 年下半年起,国内绝大部分公开 Docker 镜像加速站(包括各大高校与云厂商镜像源)被下架或限制访问,直接导致 docker pull 提示 toomanyrequests 或 Client.Timeout exceeded。
1. Windows / macOS Docker Desktop 配置方法
- 打开 Docker Desktop 界面,点击右上角 ⚙️ Settings(设置);
- 导航至 Resources(资源) ➔ Proxies(代理);
- 勾选 Manual proxy configuration(手动代理配置);
- 填入你的本地代理客户端端口(以 Clash Verge 为例):
- Web Server (HTTP):
http://127.0.0.1:7897 - Secure Web Server (HTTPS):
http://127.0.0.1:7897 - Bypass for these hosts & domains:
localhost,127.0.0.1
- Web Server (HTTP):
- 点击 Apply & restart,重启 Docker 后即可秒级拉取官方镜像。
二、npm / yarn / pnpm 命令行代理配置
bash
# 设置 npm 代理
npm config set proxy http://127.0.0.1:7897
npm config set https-proxy http://127.0.0.1:7897
# 如需取消恢复
npm config delete proxy
npm config delete https-proxy
# 设置 yarn 代理
yarn config set proxy http://127.0.0.1:7897
yarn config set https-proxy http://127.0.0.1:7897三、Python pip / conda 代理配置
bash
# 临时走代理安装单个包
pip install --proxy http://127.0.0.1:7897 torch torchvision
# 全局永久配置 pip 代理
pip config set global.proxy http://127.0.0.1:7897
# 如需取消 pip 代理
pip config unset global.proxy