CentOS 7 Docker 连接 Docker Hub 失败解决方案

CentOS 7 Docker 连接 Docker Hub 失败解决方案

摘要:本文记录 CentOS 7 系统中 Docker 无法连接 Docker Hub 的完整排查过程,最终通过配置 DaoCloud 镜像加速器解决问题。


一、问题现象

在 CentOS 7 系统上使用 Docker 搜索镜像时,出现连接被拒绝错误:

bash 复制代码
[root@localhost ~]# docker search nginx
Error response from daemon: Get "https://index.docker.io/v1/search?q=nginx&n=25": 
dial tcp 157.240.9.36:443: connect: connection refused

二、环境信息

  • 操作系统:CentOS 7 (64位)
  • Docker 版本 :(请读者自行查看 docker --version)
  • 网络环境:中国境内

三、排查过程

3.1 基础网络诊断

首先验证网络连通性:

bash 复制代码
# 测试外网连通性 - 正常
[root@localhost ~]# curl -I https://www.baidu.com
HTTP/1.1 200 OK
bash 复制代码
# 测试 Docker Hub 连接 - 失败
[root@localhost ~]# curl -4 -I https://index.docker.io/v1/
curl: (7) Failed connect to index.docker.io:443; 拒绝连接

# DNS 解析正常
[root@localhost ~]# nslookup index.docker.io
Name:   index.docker.io
Address: 199.59.150.49

初步判断:DNS 解析正常,外网连接正常,但 Docker Hub 特定连接被拒绝。


3.2 检查防火墙

检查 firewalld 和 iptables 规则:

bash 复制代码
# firewalld 状态
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Active: active (running) ...

# 查看防火墙规则
[root@localhost ~]# firewall-cmd --list-all
public (active)
  services: dhcpv6-client ssh
  ports: 

结论:iptables 没有阻止 443 端口出站规则,防火墙不是根本原因。


3.3 配置镜像加速器(第一次尝试)

尝试配置常见的国内镜像源:

bash 复制代码
cat > /etc/docker/daemon.json << 'EOF'
{
  "registry-mirrors": [
    "https://hub-mirror.c.163.com",
    "https://docker.mirrors.ustc.edu.cn"
  ]
}
EOF

systemctl restart docker

验证配置:

bash 复制代码
[root@localhost ~]# docker info | grep -A 5 "Registry Mirrors"
 Registry Mirrors:
  https://hub-mirror.c.163.com/
  https://docker.mirrors.ustc.edu.cn/

结果 :配置已生效,但 docker search nginx 仍然连接被拒绝。

网易云和中科大镜像源目前已停止服务或限制访问。


四、最终解决方案

4.1 使用 DaoCloud 镜像加速器

更换为 DaoCloud 镜像:

bash 复制代码
cat > /etc/docker/daemon.json << 'EOF'
{
  "registry-mirrors": ["https://docker.m.daocloud.io"]
}
EOF

systemctl restart docker

4.2 验证结果

bash 复制代码
[root@localhost ~]# docker search nginx
NAME                                     DESCRIPTION                                      STARS     OFFICIAL
nginx                                    Official build of Nginx.                         21186     [OK]
nginx/nginx-ingress                      NGINX and  NGINX Plus Ingress Controllers fo...   114       
nginx/nginx-prometheus-exporter          NGINX Prometheus Exporter for NGINX and NGIN...   50        
nginx/unit                               This repository is retired, use the Docker o...   66        
nginx/nginx-ingress-operator             NGINX Ingress Operator for NGINX and NGINX P...   3         
nginx/nginx-quic-qns                     NGINX QUIC interop                               1         
nginx/nginxaas-loadbalancer-kubernetes                                                    1         
nginx/unit-preview                       Unit preview features                            0         
bitnami/nginx                            Bitnami Secure Image for nginx                   202       
bitnamicharts/nginx                      Bitnami Helm chart for NGINX Open Source         3         
ubuntu/nginx                             Nginx, a high-performance reverse proxy & we...   138       
kasmweb/nginx                            An Nginx image based off nginx:alpine and in...   8         
rancher/nginx                                                                             3         
linuxserver/nginx                        An Nginx container, brought to you by LinuxS...   236       
dtagdevsec/nginx                         T-Pot Nginx                                      0  

成功! Docker 可以正常搜索和拉取镜像了。


五、总结

排查步骤 结果
网络连通性 ✅ 正常
DNS 解析 ✅ 正常
防火墙 ✅ 未阻止
网易云/中科大镜像 ❌ 已失效
DaoCloud 镜像 ✅ 可用

最终配置

文件 /etc/docker/daemon.json

json 复制代码
{
  "registry-mirrors": ["https://docker.m.daocloud.io"]
}

常用镜像源汇总(截至 2025-2026)

镜像源 地址 状态
DaoCloud https://docker.m.daocloud.io ✅ 可用
阿里云 https://<your-id>.mirror.aliyuncs.com ✅ 需注册
网易云 https://hub-mirror.c.163.com ❌ 失效
中科大 https://docker.mirrors.ustc.edu.cn ❌ 失效

六、后续使用

bash 复制代码
# 拉取镜像
docker pull nginx

# 运行容器
docker run -d -p 80:80 --name my-nginx nginx

# 查看运行状态
docker ps

提示 :如果 DaoCloud 镜像后续也失效,建议登录 阿里云容器镜像服务 获取个人专属加速地址,稳定性更高。

相关推荐
ai产品老杨4 小时前
架构师深剖:基于 Docker 容器化与边缘计算的 AI 视频管理平台——支持 GB28181/RTSP 多协议接入与全源码交付
人工智能·docker·边缘计算
qq_185198696 小时前
Docker 历史版本
docker
m0_738120726 小时前
渗透测试基础——基于Docker的Rsync服务靶场搭建与原理讲解
运维·服务器·网络·安全·web安全·docker·容器
杨浦老苏9 小时前
PDF文档管理平台PDFManager
docker·pdf·工具·群晖
ai产品老杨10 小时前
解耦异构安防:基于 Docker 与边缘计算的 AI 视频管理平台,如何实现 GB28181/RTSP 统一接入与全源码交付
人工智能·docker·边缘计算
极客先躯11 小时前
高级java每日一道面试题-2026年02月09日-实战篇[Docker]-Docker 容器有哪些安全风险?如何缓解?
java·运维·网络·安全·docker·容器
yuanzhengme11 小时前
Ollama【部署 07】搭建本地智能体的简单说明(局域网离线部署Ollama+模型迁移+Docker部署AnythingLLM)
运维·docker·容器·大模型·ollama·本地智能体
想要成为计算机高手11 小时前
用meta quest 3 遥操宇树机器人-xr_teleoperate 复现(含docker安装与配置方式)
人工智能·docker·机器人·xr·g1·具身智能
“码”力全开12 小时前
云边端协同架构:基于 Docker 与边缘计算的 GB28181/RTSP 异构视频 AI 管理平台设计(附源码交付)
人工智能·docker·架构
IVEN_12 小时前
本地正常,Docker 怎么就空白:Next.js SSR 的 Alpine musl DNS 陷阱
前端·docker·next.js