CentOS 7 Docker 連接 Docker Hub 失敗解決方案
摘要:本文記錄 CentOS 7 系統中 Docker 無法連接 Docker Hub 的完整排查過程,最終通過配置 DaoCloud 鏡像加速器解決問題。
一、問題現象
在 CentOS 7 系統上使用 Docker 搜索鏡像時,出現連接被拒絕錯誤:
[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

二、環(huán)境信息
- 操作系統:CentOS 7 (64位)
- Docker 版本:(請讀者自行查看
docker --version) - 網絡環(huán)境:中國境內
三、排查過程
3.1 基礎網絡診斷
首先驗證網絡連通性:
# 測試外網連通性 - 正常 [root@localhost ~]# curl -I https://www.baidu.com HTTP/1.1 200 OK

# 測試 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 規(guī)則:
# firewalld 狀態(tài) [root@localhost ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Active: active (running) ... # 查看防火墻規(guī)則 [root@localhost ~]# firewall-cmd --list-all public (active) services: dhcpv6-client ssh ports:
結論:iptables 沒有阻止 443 端口出站規(guī)則,防火墻不是根本原因。
3.3 配置鏡像加速器(第一次嘗試)
嘗試配置常見的國內鏡像源:
cat > /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
EOF
systemctl restart docker驗證配置:
[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 鏡像:
cat > /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": ["https://docker.m.daocloud.io"]
}
EOF
systemctl restart docker4.2 驗證結果
[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:
{
"registry-mirrors": ["https://docker.m.daocloud.io"]
}常用鏡像源匯總(截至 2025-2026)
| 鏡像源 | 地址 | 狀態(tài) |
|---|---|---|
| DaoCloud | https://docker.m.daocloud.io | ? 可用 |
| 阿里云 | https://<your-id>.mirror.aliyuncs.com | ? 需注冊 |
| 網易云 | https://hub-mirror.c.163.com | ? 失效 |
| 中科大 | https://docker.mirrors.ustc.edu.cn | ? 失效 |
六、后續(xù)使用
# 拉取鏡像 docker pull nginx # 運行容器 docker run -d -p 80:80 --name my-nginx nginx # 查看運行狀態(tài) docker ps
提示:如果 DaoCloud 鏡像后續(xù)也失效,建議登錄 阿里云容器鏡像服務 獲取個人專屬加速地址,穩(wěn)定性更高。
到此這篇關于CentOS 7 Docker 連接 Docker Hub 失敗解決方案的文章就介紹到這了,更多相關Docker Hub 連接失敗內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Spring Boot 2.4 新特性之一鍵構建Docker鏡像的過程詳解
這篇文章主要介紹了Spring Boot 2.4 新特性之一鍵構建Docker鏡像的過程詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12

