Docker执行hello-world报错&Docker镜像源DNS解析异常处理

Docker执行hello-world报错

powershell 复制代码
[root@xxx ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

解决办法

  1. 使用有效的镜像加速器

创建或编辑 daemon.json 文件(有则编辑无则创建)

powershell 复制代码
vim /etc/docker/daemon.json

配置一个正确的国内镜像加速器

镜像加速器获取途径:可以在购买的云服务器后台搜索"容器镜像服务"->找到"镜像加速器"里面有详细步骤

powershell 复制代码
{
  "registry-mirrors": [
    "https://docker.m.daocloud.io"
  ]
}
  1. 执行重新加载系统配置文件
powershell 复制代码
systemctl daemon-reload
  1. 执行重启docker
powershell 复制代码
systemctl restart docker
  1. 验证是否生效,查看包含镜像地址的所有行
powershell 复制代码
docker info | grep -A 5 "Registry Mirrors"

5.重新运行hello-world

powershell 复制代码
docker run hello-world

6.如果还报错,可能是DNS解析异常或镜像源失效

运行 curl 命令测试DNS是否解析成功

powershell 复制代码
curl -I --connect-timeout 5 https://docker.m.daocloud.io
powershell 复制代码
#如果运行后报如下错误,则确认DNS解析异常或镜像源失效
[root@xxx ~]# curl -I --connect-timeout 5 https://docker.m.daocloud.io
curl: (6) Could not resolve host: docker.m.daocloud.io

7.确认镜像源是否失效

可直接在浏览器中输入镜像源地址如: https://docker.m.daocloud.io 地址访问,页面显示 无法访问此网站 则证明镜像源已失效

8.如镜像源有效,则是DNS配置的问题

可以查看DNS配置文件

powershell 复制代码
vim /etc/resolv.conf

以我的resolv.conf文件为例,内容如下

powershell 复制代码
# Generated by NetworkManager
search openstacklocal
nameserver 100.125.1.250
options timeout:1 single-request-reopen 

此时可以发现nameserver 100.125.1.250是某某云内网服务IP,所以解析异常

我们需要新增公共DNS服务器作为备用,我选择的是 8.8.8.8 全球最知名的公共DNS,大家可按需选择,此DNS服务器作用是会在主DNS无响应时介入

修改后的内容如下

powershell 复制代码
# Generated by NetworkManager
search openstacklocal
#此DNS服务器是某某云内网的
nameserver 100.125.1.250
#新增备用DNS
nameserver 8.8.8.8 
# 将超时从1秒改为2秒
options timeout:2 single-request-reopen 

9.保存文件并立即测试

保存修改后,运行以下命令验证解析是否恢复正常:

powershell 复制代码
curl -I --connect-timeout 5 https://docker.m.daocloud.io

正常结果:curl 应返回 HTTP/1.1 200 OK 或 302 等成功状态码,返回成功后再次运行 docker run hello-world 即可

相关推荐
handsomestWei3 小时前
Docker引擎API接入配置
运维·http·docker·容器·api
si莉亚3 小时前
ROS2安装EVO工具包
linux·开发语言·c++·开源
Tingjct3 小时前
Linux常用指令
linux·运维·服务器
广州灵眸科技有限公司3 小时前
为RK3588注入澎湃算力:RK1820 AI加速卡完整适配与评测指南
linux·网络·人工智能·物联网·算法
IT界的老黄牛3 小时前
Linux 压缩命令实战:tar、gzip、bzip2、xz、zstd 怎么选?一篇讲清楚
linux·运维·服务器
IT WorryFree4 小时前
飞塔防火墙与第三方设备进行IPSEC故障诊断期间,用户可能会观察到以下错误:
linux·服务器·网络
12345,catch a tiger4 小时前
虚拟机ubuntu安装Vmware Tools
linux·运维·ubuntu
凉、介4 小时前
别再把 PCIe 的 inbound/outbound、iATU 和 eDMA 混为一谈
linux·笔记·学习·嵌入式·pcie
辰风沐阳4 小时前
OpenClaw 安装教程(Ubuntu 24.04 Desktop)
linux·ubuntu
嘿嘿嘿x35 小时前
Linux记录过程
linux·开发语言