docker拉取失败,更换docker的源方式

 更新时间:2025年11月08日 15:14:12   作者:return(b,a%b);  
文章讨论了Docker客户端访问DockerHub或其他注册中心时遇到的错误,并提供了五种解决方法,包括检查网络、docker状态、更换源、重载和重启Docker服务以及重新执行docker pull hello-world命令

docker拉取失败,更换docker的源

docker pull hello-world时报错
hh@hh-virtual-machine:~$ docker pull hello-world
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded


hh@hh-virtual-machine:~$ docker pull registry.cn-hangzhou.aliyuncs.com/library/ubuntu:22.04
Error response from daemon: pull access denied for registry.cn-hangzhou.aliyuncs.com/library/ubuntu, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

这个错误表明Docker客户端尝试访问Docker Hub或其他Docker注册中心时出现了问题。

具体来说,是在尝试获取注册中心API的响应时遇到了错误。

可能的原因包括网络问题、认证问题、注册中心URL不正确或者注册中心服务本身不可用。

解决方法

检查网络

hh@hh-virtual-machine:~$ ping www.baidu.com
PING www.wshifen.com (119.63.197.151) 56(84) bytes of data.
64 bytes from 119.63.197.151 (119.63.197.151): icmp_seq=1 ttl=49 time=161 ms
64 bytes from 119.63.197.151 (119.63.197.151): icmp_seq=2 ttl=49 time=164 ms
64 bytes from 119.63.197.151 (119.63.197.151): icmp_seq=3 ttl=49 time=160 ms
^C
--- www.wshifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 160.431/161.615/163.762/1.520 ms

检查docker状态

hh@hh-virtual-machine:~$ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2025-11-07 14:02:48 CST; 17min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1335 (dockerd)
      Tasks: 16
     Memory: 122.3M
        CPU: 1.526s
     CGroup: /system.slice/docker.service
             └─1335 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

11月 07 14:18:15 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:15.098431463+08:00" level=error msg="Handler for POST /v1.51/images/create returned error: Get \"https://hub-mirror.c.163.com/v2/\": dial tcp: lookup hub-mirror.c.163.com on 127>
11月 07 14:18:36 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:36.217686088+08:00" level=warning msg="Error getting v2 registry: Get \"https://docker.mirrors.ustc.edu.cn/v2/\": dial tcp: lookup docker.mirrors.ustc.edu.cn on 127.0.0.53:53: n>
11月 07 14:18:36 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:36.217749899+08:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://docker.mirrors.ustc.edu.cn/v2/\": dial tcp: lookup docker.mirrors.ustc.edu.cn on>
11月 07 14:18:36 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:36.269239801+08:00" level=warning msg="Error getting v2 registry: Get \"https://hub-mirror.c.163.com/v2/\": dial tcp: lookup hub-mirror.c.163.com on 127.0.0.53:53: no such host"
11月 07 14:18:36 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:36.269318729+08:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://hub-mirror.c.163.com/v2/\": dial tcp: lookup hub-mirror.c.163.com on 127.0.0.53:>
11月 07 14:18:51 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:51.271108112+08:00" level=warning msg="Error getting v2 registry: Get \"https://registry.docker-cn.com/v2/\": net/http: request canceled while waiting for connection (Client.Tim>
11月 07 14:18:51 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:18:51.271180286+08:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://registry.docker-cn.com/v2/\": net/http: request canceled while waiting for conne>
11月 07 14:19:06 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:19:06.271769052+08:00" level=warning msg="Error getting v2 registry: Get \"https://registry-1.docker.io/v2/\": context deadline exceeded"
11月 07 14:19:06 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:19:06.271862946+08:00" level=info msg="Attempting next endpoint for pull after error: Get \"https://registry-1.docker.io/v2/\": context deadline exceeded"
11月 07 14:19:06 hh-virtual-machine dockerd[1335]: time="2025-11-07T14:19:06.273537816+08:00" level=error msg="Handler for POST /v1.51/images/create returned error: Get \"https://registry-1.docker.io/v2/\": context deadline exceeded"

更换源

systemctl status docker
sudo mkdir -p /etc/docker
vim /etc/docker/daemon.json  
添加:
{
  "registry-mirrors" : ["https://docker.registry.cyou",
"https://docker-cf.registry.cyou",
"https://dockercf.jsdelivr.fyi",
"https://docker.jsdelivr.fyi",
"https://dockertest.jsdelivr.fyi",
"https://mirror.aliyuncs.com",
"https://dockerproxy.com",
"https://mirror.baidubce.com",
"https://docker.m.daocloud.io",
"https://docker.nju.edu.cn",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.mirrors.ustc.edu.cn",
"https://mirror.iscas.ac.cn",
"https://docker.rainbond.cc",
"https://do.nark.eu.org",
"https://dc.j8.work",
"https://dockerproxy.com",
"https://gst6rzl9.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"http://mirrors.ustc.edu.cn/",
"https://mirrors.tuna.tsinghua.edu.cn/",
"http://mirrors.sohu.com/"  
],
 "insecure-registries" : [
    "registry.docker-cn.com",
    "docker.mirrors.ustc.edu.cn"
    ],
"debug": true,
"experimental": false
}

重载和重启dockers服务

sudo systemctl daemon-reload
sudo systemctl restart docker
docker info

重新执行

docker pull hello-world

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • docker 容器上编译 go 程序提示找不到文件问题

    docker 容器上编译 go 程序提示找不到文件问题

    这篇文章主要介绍了docker 容器上编译 go 程序无法运行提示找不到文件问题,解决方法也很简单,感兴趣的朋友跟随脚本之家小编一起看看吧
    2018-05-05
  • Docker 退出container后保持继续运行的操作

    Docker 退出container后保持继续运行的操作

    这篇文章主要介绍了Docker 退出container后保持继续运行的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2021-03-03
  • docker tag和docker push的使用详解

    docker tag和docker push的使用详解

    这篇文章主要介绍了docker tag和docker push的使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-09-09
  • Docker拉取镜像超时的原因分析与解决方法

    Docker拉取镜像超时的原因分析与解决方法

    这篇文章主要为大家详细介绍了Docker在拉取镜像时超时的相关原因分析与解决方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下
    2025-04-04
  • 使用phpstorm对docker中的脚本进行debug的方法

    使用phpstorm对docker中的脚本进行debug的方法

    这篇文章主要介绍了使用phpstorm对docker中的脚本进行debug的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08
  • docker在win10家庭版下构建laravel开发环境的教程详解

    docker在win10家庭版下构建laravel开发环境的教程详解

    这篇文章主要介绍了docker在win10家庭版下构建laravel开发环境,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-06-06
  • 一文学会docker 安装mysql的方法

    一文学会docker 安装mysql的方法

    这篇文章主要介绍了docker 安装 mysql的方法,通过使用docker命令下载mysql接着使用docker命令创建实例并启动,对docker 安装 mysql相关知识感兴趣的朋友一起看看吧
    2022-04-04
  • 在 Docker 容器中运行 PHPMyAdmin的详细步骤

    在 Docker 容器中运行 PHPMyAdmin的详细步骤

    Docker是一个开源的应用容器引擎,它能够实现应用部署的自动化。此外,容器是完全使用沙箱机制,容器之间的环境相互独立,不会相互干扰,接下来通过本文给大家介绍在 Docker 容器中运行 PHPMyAdmin的详细步骤,感兴趣的朋友一起看看吧
    2022-01-01
  • Docker在WSL环境下启动失败的问题解决办法

    Docker在WSL环境下启动失败的问题解决办法

    在Windows系统上,有时候我们可能会遇到Docker启动失败的问题,特别是在使用WSL(Windows Subsystem for Linux)作为Docker运行环境时,这篇文章主要介绍了Docker在WSL环境下启动失败问题的解决办法,需要的朋友可以参考下
    2025-07-07
  • 在Kubernetes环境下使用Docker实现GPU支持的完整方案

    在Kubernetes环境下使用Docker实现GPU支持的完整方案

    本文将介绍如何在 Kubernetes 环境下,使用 Docker 容器运行时实现 NVIDIA GPU 加速支持,包括环境准备、安装 nvidia-docker2、K8s device plugin 配置等内容,需要的朋友可以参考下
    2025-05-05

最新评论