Docker运行hello-world镜像失败或超时的问题

 更新时间:2024年09月18日 10:20:07   作者:wang-1303  
在安装Docker并尝试运行hello-world时,可能会遇到超时问题,这通常是由于默认的镜像源访问速度慢造成的,解决这个问题的办法是更换镜像源,虽然许多人推荐使用阿里云的镜像源,对Docker hello-world超时问题感兴趣的朋友一起看看吧

docker run hello-world时超时告警

​ 跟着官方文档进行docker安装时,测试docker是否运行成功执行docker run hello-world时,结果和别人的不一样

正常情况:

我们的:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Retrying in 10 seconds 
docker: error pulling image configuration: download failed after attempts=6: dial tcp 128.242.245.93:443: connect: connection refused.
See 'docker run --help'.

原因:就是我们的镜像源不行,需要更换镜像源

但是我们就算知道原因,去找度娘会发现大部分都是说更换阿里的镜像源,但是我们尝试之后并没有作用

常规方案没作用

#针对Docker客户端版本大于 1.10.0 的用户
#您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://5nkcn10r.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

2.1、解决方案

配置加速地址:设置registry mirror

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl status docker

重启完docker之后检查registry mirror刚刚配置的加速地址是否成功

[root@wzy1303 docker]# docker info
Client: Docker Engine - Community
 Version:    26.1.4
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 26.1.4
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d2d58213f83a351ca8f528a95fbd145f5654e957
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
 Kernel Version: 3.10.0-1160.119.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64
 CPUs: 8
 Total Memory: 2.761GiB
 Name: wzy1303
 ID: 74efae68-ef43-45a9-b547-ffa2c3805423
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: inkling1303
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://do.nark.eu.org/
  https://dc.j8.work/
  https://docker.m.daocloud.io/
  https://dockerproxy.com/
  https://docker.mirrors.ustc.edu.cn/
  https://docker.nju.edu.cn/
 Live Restore Enabled: false

可以看到我们已经配置成功:

运行docker run hello-world,成功运行

[root@wzy1303 docker]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:53cc4d415d839c98be39331c948609b659ed725170ad2ca8eb36951288f81b75
Status: Downloaded newer image for hello-world:latest
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/
For more examples and ideas, visit:
 https://docs.docker.com/get-started/
#查看是否成功拉取hello-world镜像
[root@wzy1303 docker]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   15 months ago   13.3kB
[root@wzy1303 docker]# docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   15 months ago   13.3kB
[root@wzy1303 docker]# docker images -aq
d2c94e258dcb

到此这篇关于Docker运行hello-world镜像失败或超时的问题的文章就介绍到这了,更多相关Docker hello-world超时内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • 如何使用docker搭建upload-labs

    如何使用docker搭建upload-labs

    upload-labs是一个使用php语言编写的,专门收集渗透测试和CTF中遇到的各种上传漏洞的靶场,旨在帮助大家对上传漏洞有一个全面的了解,本文给大家介绍使用 Docker 搭建 upload-labs 的步骤,感兴趣的朋友一起看看吧
    2024-03-03
  • Docker部署portainer的详细步骤

    Docker部署portainer的详细步骤

    Portainer是一个轻量级的docker环境管理UI,可以用来管理docker宿主机和docker swarm集群,今天通过本文给大家介绍Docker部署portainer的步骤,感兴趣的朋友一起看看吧
    2022-01-01
  • Docker搭建服务器监控面板的实现示例

    Docker搭建服务器监控面板的实现示例

    Docker服务器监控面板是一种用于监控容器运行情况的工具,本文主要介绍了Docker搭建服务器监控面板的实现示例,具有一定的参考价值,感兴趣的可以了解一下
    2024-01-01
  • docker中的jenkins配置sonarQube的过程

    docker中的jenkins配置sonarQube的过程

    SonarQube是一个开源的代码分析平台,用来持续分析和评测项目源代码的质量,通过SonarQube可以检测出项目中重复代码,潜在bug, 代码规范,安全性漏洞等问题,并通过SonarQube web UI展示出来,这篇文章主要介绍了docker中的jenkins配置sonarQube,需要的朋友可以参考下
    2023-08-08
  • Docker查看容器IP地址的方法实现

    Docker查看容器IP地址的方法实现

    本文主要介绍了Docker查看容器IP地址的方法实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2023-06-06
  • Docker安装php及yaf扩展文件内容

    Docker安装php及yaf扩展文件内容

    这篇文章主要为大家介绍了Docker安装php及yaf扩展文件内容,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-11-11
  • Ubuntu正确安装Docker和Docker Compose的步骤详细讲解

    Ubuntu正确安装Docker和Docker Compose的步骤详细讲解

    Docker Compose是一个用于定义和运行多容器Docker应用的工具,这篇文章主要介绍了Ubuntu正确安装Docker和Docker Compose的相关资料,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2025-11-11
  • 使用Docker快速搭建你的Gitbook

    使用Docker快速搭建你的Gitbook

    这篇文章主要介绍了使用Docker快速搭建你的Gitbook的相关资料,需要的朋友可以参考下
    2023-11-11
  • 如何在Ubuntu安装docker以及一些常见报错

    如何在Ubuntu安装docker以及一些常见报错

    这篇文章主要介绍了在Ubuntu上安装Docker的步骤,包括前置工作、安装、检查安装结果、常见报错处理以及一些实用的配置和修改,如修改镜像源和目录,需要的朋友可以参考下
    2025-04-04
  • docker镜像访问本地elasticsearch端口操作

    docker镜像访问本地elasticsearch端口操作

    这篇文章主要介绍了docker镜像访问本地elasticsearch端口操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11

最新评论