解决docker配置了镜像源但还会拉取官方镜像源的问题

🏓我们有时候虽然配置了Docker国内镜像源,但是还是会绕过去请求官方镜像源(docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded),现在我们就来解决一下,这是其中的一个解决方案,仅供参考:

1、先诊断一下网络有没有问题,一般是不会有问题的

bash 复制代码
ping -c 3 8.8.8.8  # 测试基本互联网连接

nslookup registry-1.docker.io  # 测试Docker Hub域名解析

curl -I --connect-timeout 10 https://registry-1.docker.io/v2/ # HTTP连接测试

2、分析现有的Docker配置

bash 复制代码
cat /etc/docker/daemon.json

这个镜像源是免费的,也比较稳定,大家可以试试:https://docker.xuanyuan.me/

🧨我们在daemon.json中做了如下配置:

javascript 复制代码
{
    "registry-mirrors": [
        "https://registry.cn-hangzhou.aliyuncs.com",
        "https://mirror.ccs.tencentyun.com",
        "https://ccr.ccs.tencentyun.com"
    ],
    "dns": ["8.8.8.8", "114.114.114.114"], # 添加DNS配置
    
    # 优化并发设置
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 5
}

3、测试验证

bash 复制代码
# 加载配置文件
sudo systemctl daemon-reload
# 重启docker
sudo systemctl restart docker

# 验证配置生效
docker info | grep -A 5 "Registry Mirrors"

# 最终功能测试
timeout 30 docker run hello-world

✨到这里如果有以下输出,就表示更换镜像源已经完成了!

bash 复制代码
Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/
相关推荐
云原生指北2 小时前
Apple Container Machine:把 Linux 搬进 Mac
macos·docker
隐层漫游者6 小时前
2026全网最细Docker容器化实战!从安装配置到Milvus向量数据库部署,一文掌握核心精髓(建议收藏)
docker
加加and减减8 小时前
Docker真实安装mysql8教程并优化配置
运维·mysql·docker·容器
半夜燃烧的香烟9 小时前
docker 安装minio nginx,配置nginx根据文根路由minio展示图片
java·nginx·docker
qiuziqiqi10 小时前
ocker-compose.yml 和Dockerfile 区别
运维·docker·容器
“码”力全开10 小时前
【架构深探】基于Docker与GB28181/RTSP的边缘计算AI视频管理平台:异构算力调度与源码交付实践
人工智能·docker·架构
qq75903536611 小时前
2026 docker run启动的容器通过命令导出为docker-composer.yml文件
docker·eureka·composer
极客先躯12 小时前
高级java每日一道面试题-2026年02月03日-实战篇[Docker]-如何备份和恢复 Docker Volume?
运维·docker·容器·自动化·备份·持久化·恢复
“码”力全开12 小时前
基于 Docker 与边缘计算的 AI 视频管理平台:打破 GB28181/RTSP 协议壁垒与源码交付架构解析
人工智能·docker·边缘计算
江湖有缘12 小时前
自建私有任务管理平台|Docker Compose部署Ticky完整教程
运维·docker·容器