macOS + Colima 下docker pull超时问题排查总结
一、问题现象
在 macOS 上使用colima运行 Docker service 时,执行:
docker pull BALABALA报错:
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)二、核心结论(先给答案)
Docker daemon 无法直连 Docker Hub,必须通过代理访问,但 daemon 并没有正确使用代理配置
shell / curl 能走代理 ≠ Docker daemon 会走代理
必须通过systemd给 Docker daemon 显式配置代理。
三、完整排查思路
1️⃣ 确认是否是网络问题,而非镜像本身
docker pull hello-world- 同样超时 → 不是镜像名问题,而是 Docker 出网问题
2️⃣ 进入 Colima VM,直接测试网络
colimasshDNS 测试(正常)
getent hosts registry-1.docker.io# 也可以 nslookup→ 能解析到 IP,说明DNS 正常
HTTPS 连通性测试(关键)
curl-Iv https://registry-1.docker.io/v2/输出显示:
Uses proxy env variable https_proxy == 'http://PROXY_INFO_HERE' CONNECT registry-1.docker.io:443→ curl 在通过代理访问 Docker Hub
3️⃣ 判断:是否“必须走代理”
清空所有代理变量,强制直连:
env-u https_proxy -u http_proxy -u all_proxy -u no_proxy\-u HTTPS_PROXY -u HTTP_PROXY -u ALL_PROXY -u NO_PROXY\curl-Iv https://registry-1.docker.io/v2/ --max-time15结果:
Connection timed out✅ 结论明确:
直连 Docker Hub 会超时,必须通过代理访问
4️⃣ 问题根因定位
查看 VM 内环境变量:
env|egrep-i"https?_proxy|all_proxy|no_proxy"HTTPS_PROXY=http://HERE https_proxy=http://ARE http_proxy=http://MY HTTP_PROXY=http://PROXY➡️Shell / curl 有代理
⚠️但 Docker daemon 并不会自动继承这些环境变量
四、最终解决方案(关键步骤)
✅ 通过 systemd 给 Docker daemon 固化代理配置
colimasshsudomkdir-p /etc/systemd/system/docker.service.d创建代理配置:
sudotee/etc/systemd/system/docker.service.d/proxy.conf>/dev/null<<'EOF' [Service] Environment="HTTP_PROXY=http://PROXY" Environment="HTTPS_PROXY=http://HERE" Environment="NO_PROXY=localhost,127.0.0.1" EOF让 systemd 重新加载并重启 Docker:
sudosystemctl daemon-reloadsudosystemctl restart dockerexit✅ 验证配置是否生效
colimassh-- systemctl show docker -p Environment确认能看到:
Environment=HTTP_PROXY=... HTTPS_PROXY=...✅ 最终验证
docker pull sean908/THE_IMAGE_YOU_NEED🎉拉取成功,问题解决
五、关键经验总结(非常重要)
1️⃣ macOS 上的代理 ≠ Colima VM 的代理
2️⃣ Shell 的代理 ≠ Docker daemon 的代理
3️⃣ Docker daemon 必须用 systemd 显式配置代理
4️⃣ 排查顺序永远是:
DNS → 直连 → 代理 → daemon 是否真正使用代理
六、TL;DR
在 Colima / Lima / Linux VM 中,
docker pull超时,90% 是 Docker daemon 没正确走代理;curl 能通不代表 docker 能通。