解决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/
相关推荐
EterNity_TiMe_44 分钟前
Docker服务越装越多记不住端口?我用Fenrus把NAS里的常用入口整理成一个导航页
运维·人工智能·docker·ai·容器·cpolar
吴声子夜歌1 小时前
Docker入门与实战——libnetwork插件化网络功能
网络·docker·容器
江湖有缘2 小时前
Docker实战 | 使用Docker部署HarborGuard容器安全扫描平台
安全·docker·容器
江湖有缘2 小时前
Docker实战 | 使用Docker部署Reubah文件转换器和图像处理器
docker·容器·eureka
骑着蜗牛撵大象3273 小时前
ToolJet + PostgreSQL:后台表格、查询和流程,一次搭成可远程访问的业务系统
数据库·低代码·docker·postgresql·内部工具·tooljet
flytalei4 小时前
从 Docker Compose 到 K3s:逐浪笔记首次完整部署与故障排查实战
笔记·docker·容器
吴声子夜歌5 小时前
Docker入门与实战——高级网络功能
网络·docker
JavaPub-rodert14 小时前
Docker 日志为什么能把磁盘写爆?讲透 json-file、local、journald、日志轮转与 docker logs
docker·eureka·json
人生匆匆15 小时前
docker部署ceph集群
ceph·docker·容器
张张123y18 小时前
后端第九课:部署上线(把你的 FastAPI 后端真正跑起来给别人用)
python·docker·部署·fastapi