Docker 拉取配置教程:解决镜像拉取连接超时问题

Docker 拉取配置教程:解决镜像拉取连接超时问题

bash 复制代码
docker pull vllm/vllm-openai:latest

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 通过代理服务器拉取镜像

1. 创建并配置代理配置文件

Docker 服务使用 systemd 管理,若需通过 HTTP 代理拉取镜像,需创建或修改配置文件:

bash 复制代码
sudo mkdir -p /etc/systemd/system/docker.service.d

sudo vim /etc/systemd/system/docker.service.d/http-proxy.conf

文件内容如下:

ini 复制代码
[Service]
Environment="HTTP_PROXY=http://proxyclient:xxx@xxx1:8080"
Environment="HTTPS_PROXY=http://proxyclient:xxx@xxx:8080"
Environment="NO_PROXY=localhost,127.0.0.1,.example.com"

说明:

  • HTTP_PROXY 和 HTTPS_PROXY:设置代理服务器地址及认证信息;
  • NO_PROXY:设置不走代理的地址列表,逗号分隔,支持 IP、域名、通配符。

2. 重载配置并重启 Docker 服务

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

⚠️ 注意:修改完代理配置后,必须执行 daemon-reload,否则配置不会生效。


二、验证代理配置是否生效

1. 检查环境变量是否加载

bash 复制代码
systemctl show --property Environment docker

输出示例:

复制代码
Environment=HTTP_PROXY=http://proxyclient:xxx@xxx:8080 
HTTPS_PROXY=http://proxyclient:xxx@xxx:8080 NO_PROXY=localhost,127.0.0.1,.example.com

2. 使用 docker info 查看代理设置

bash 复制代码
docker info | grep Proxy

输出示例:

复制代码
HTTP Proxy: http://xxxxx:xxxxx@xxx:8080
HTTPS Proxy: http://xxxxx:xxxxx@xxx:8080
No Proxy: localhost,127.0.0.1,.example.com

三、配置 Docker 镜像加速器

1. 修改 Docker 守护进程配置文件

bash 复制代码
sudo vim /etc/docker/daemon.json

添加镜像加速器地址(如阿里云):

json 复制代码
{
  "registry-mirrors": ["https://qrdh9sev.mirror.aliyuncs.com"],
  "runtimes": {
    "nvidia": {
      "args": [],
      "path": "nvidia-container-runtime"
    }
  }
}

or

json 复制代码
{
    "runtimes": {
        "nvidia": {
            "args": [],
            "path": "nvidia-container-runtime"
        }
    },
     "registry-mirrors": [
       "https://docker.xuanyuan.me",
       "https://docker.1ms.run",
       "https://pee6w651.mirror.aliyuncs.com",
       "https://registry.docker-cn.com",
       "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn",
        "https://hub-mirror.c.163.com",
        "https://mirror.baidubce.com",
        "https://ml91x5p1.mirror.aliyuncs.com"
  ]
}

说明:

  • registry-mirrors:设置 Docker Hub 的镜像加速地址;
  • 可根据实际使用的服务提供商替换为其他加速地址。

2. 重启 Docker 服务

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

四、测试

bash 复制代码
docker pull vllm/vllm-openai:latest

latest: Pulling from vllm/vllm-openai

8f84a9f2102e: Pulling fs layer 
b95112eaf283: Pulling fs layer 
030ef8250936: Pulling fs layer 
72ac9ccfda38: Waiting 
73389fbd088f: Pull complete 
0264850675f7: Pull complete 
de1d03310308: Pull complete 

78b596bcad08: Waiting 
6a16eaeb9de9: Waiting 
latest: Pulling from vllm/vllm-openai
8f84a9f2102e: Pulling fs layer 
b95112eaf283: Pulling fs layer 
030ef8250936: Pulling fs layer 
72ac9ccfda38: Pulling fs layer 
73389fbd088f: Pull complete 

78b596bcad08: Pull complete 
6a16eaeb9de9: Pull complete 
Digest: sha256:014a95f21c9edf6abe0aea6b07353f96baa4ec291c427bb1176dc7c93a85845c
Status: Downloaded newer image for vllm/vllm-openai:latest
docker.io/vllm/vllm-openai:latest

五、排查 Docker 连接问题的基本步骤

1. 检查 Docker 守护进程状态

bash 复制代码
systemctl status docker

若服务未运行,尝试重启:

bash 复制代码
sudo systemctl start docker

2. 查看 Docker 日志

bash 复制代码
journalctl -u docker.service -n 100

或:

bash 复制代码
sudo docker info

查找类似错误信息:

复制代码
Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection

3. 确认网络设置

  • 确认服务器可访问 https://registry-1.docker.io;
  • 检查 DNS 解析是否正常;
  • 使用 curl 测试代理:
bash 复制代码
curl -x http://proxyclient:xxx@xxx:8080 https://registry-1.docker.io/v2/

4. 检查 Docker 配置文件语法

bash 复制代码
sudo dockerd --test --config-file /etc/docker/daemon.json

若报错,说明配置文件语法错误。


六、总结与建议

问题 解决方案
Docker 拉取超时 检查代理配置、镜像加速器、网络连接
Docker 守护进程异常 检查日志、重启服务、验证配置
vllm 拉取失败 确认镜像地址、标签是否正确;尝试使用代理或镜像加速器
Docker 无法连接 检查 docker.sock 权限、守护进程状态

建议:

  • 使用镜像加速器 + 代理配置双保险;
  • 大镜像建议在夜间或低峰期拉取;
  • 定期检查 Docker 配置文件与服务状态。

七、进一步排查命令

bash 复制代码
systemctl status docker
journalctl -u docker.service -b

如需进一步优化或排查问题,可结合 journalctl -xe 查看详细日志。

相关推荐
志栋智能27 分钟前
超自动化安全的报告自动生成与分发
运维·安全·自动化
小敬爱吃饭1 小时前
PgHero轻量PostgreSQL监控:Docker部署、连接统计与执行计划
数据库·docker·postgresql
开开心心就好3 小时前
定时结束进程的小工具,到点还能关机
linux·运维·服务器·智能手机·pdf·电脑·word
风翼靓崽3 小时前
ansible
linux·运维·ansible
遨游DATA3 小时前
容器退出码 126 排查:静态资源镜像层如何改写目录权限
linux·docker·kubernetes·文件权限
有个傻瓜3 小时前
容器里时间凭空差 8 小时:naive 与 aware 时区混用排错复盘与四种方案实测
python·docker·springboot·时区排错·naive/aware
zhengfei6115 小时前
AI 渗透项目深度研究:从工具自动化到自主攻击系统,下一代 AI 渗透平台应该如何构建?
运维·人工智能·ai·开源·自动化·ai编程·ai-native
zz0723206 小时前
深入浅出 Nginx:核心原理与企业级应用
运维·nginx
cndes7 小时前
出现 2013 lost connection to MySQL server during query
运维·服务器·数据库
江湖有缘7 小时前
Anchor私有化部署实战:Docker搭建专属个人笔记服务
笔记·docker·容器