centos7 使用docker run hello-world报错,无法获取镜像

本文介绍了一种解决Docker在拉取镜像时遇到超时错误的方法,通过配置DNS为8.8.8.8并重启服务,成功解决了Docker无法从Docker Hub拉取'hello-world'镜像的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误示例:

[root@localhost /]# 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'.

查找过程就不多说了,直接说解决方法:

[root@localhost network-scripts]# vi ifcfg-ens33 
DNS1=8.8.8.8

配置DNS=8.8.8.8,然后重启服务。
在运行即可,如下:

[root@localhost network-scripts]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:92695bc579f31df7a63da6922075d0666e565ceccad16b59c3374d2cf4e8e50e
Status: Downloaded newer image for hello-world:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.

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.
    (amd64)
 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://hub.docker.com/

### 解决方案 当尝试通过 `sudo docker run hello-world` 命令启动容器并遇到错误时,可能的原因包括网络连接问题、DNS解析失败或Docker配置不当。以下是几种常见情况及其对应的解决方案。 #### DNS解析失败 如果收到类似于“no such host”的错误消息,则可能是由于本地计算机无法正确解析域名造成的。可以考虑修改系统的 `/etc/resolv.conf` 文件来指定可靠的公共DNS服务器地址,例如Google提供的8.8.8.8[^3]。 ```bash echo 'nameserver 8.8.8.8' | sudo tee /etc/resolv.conf > /dev/null ``` #### 网络超时 对于TLS握手超时的情况,这通常意味着客户端与远程主机之间的安全通信建立过程出现了延迟或者中断。一种方法是增加环境变量中的HTTP(S)_PROXY设置以改善对外部资源访问的速度和稳定性;另一种更简单的办法是在国内环境中利用加速器服务提供商所提供的镜像站点作为替代源[^2]。 按照以下步骤操作: 1. 打开终端窗口; 2. 编辑Docker守护程序的JSON配置文件(一般位于`/etc/docker/daemon.json`),如果没有该文件则创建它; 3. 添加如下内容到此文件内: ```json { "registry-mirrors": ["https://hub.atomgit.com"] } ``` 4. 使用命令重启Docker服务使更改生效: ```bash sudo systemctl restart docker ``` 以上措施应该能够有效缓解因网络状况不佳而导致的问题,并允许顺利拉取所需的Hello World测试镜像
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值