解决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/
相关推荐
江湖有缘7 分钟前
Lunalytics部署指南:使用Docker快速搭建私有监控面板
运维·docker·容器
分布式存储与RustFS32 分钟前
RustFS保姆级教程:Docker快速部署兼容S3的本地对象存储
运维·docker·容器·rustfs部署教程·本地搭建s3对象存储·rustfs网页控制台使用·awscli连接rustfs
江湖有缘32 分钟前
Docker部署Papra极简文件归档平台
运维·docker·容器
qq_349447952 小时前
十四、k8s集群安装kube-state-metrics 组件
docker·容器·kubernetes
必胜刻3 小时前
从零搭建全栈博客系统:Go + Vue 3 + Docker 全流程实战
vue.js·docker·golang
我叫张小白。3 小时前
Docker镜像构建原理与Dockerfile工程化实践深度剖析
运维·docker·容器
梦想的颜色12 小时前
硬核实践:使用 Docker 部署生产级 Redis(持久化 + 安全配置 + 高可用)
redis·docker·redis持久化·docker compose·redis哨兵·rdb aof
weixin_4713830312 小时前
Docker - 05 - 构建流程
运维·docker·容器
ejinxian16 小时前
微虚拟机 smolvm 与Docker 容器比较
运维·docker·容器·smolvm
爱码少年16 小时前
Docker如何一次查看多个容器日志
运维·docker·容器