解决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/
相关推荐
云川之下1 小时前
【k8s】Docker inspect 命令
docker·容器·kubernetes
倔强的石头1063 小时前
飞牛OS部署Mtab:Docker搭建自托管书签导航并实现远程访问
运维·docker·容器
apgk118 小时前
基于Canal实现mysql数据同步到消息队列(RabbitMQ/Kafka)详细操作教程
docker·kafka·rabbitmq
fatcoder18 小时前
玩转Docker 06 — 容器网络
前端·后端·docker
AR_xsy19 小时前
docker--资源配额 配置
运维·docker·容器
国际云,接待20 小时前
Docker 容器突然退出、服务莫名重启:从 OOMKilled 到内存泄漏的生产排查手册
运维·docker·容器
橙-极纪元20 小时前
把docker的镜像文件从一台服务器中,迁移至另一台服务器
服务器·docker·容器
雨声不在1 天前
docker-android 重启后镜像起不来
android·docker·容器
宋辰轩1 天前
Docker导致的wsl2崩溃问题
docker·wsl2
码农阿豪1 天前
Ubuntu部署GodoOS:Docker搭建Web办公桌面并实现远程访问
前端·ubuntu·docker