docker run hello-world失败、报错

若终端输出类似以下信息,一般是docker镜像源未设置或有问题

bash 复制代码
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'.

解决方案:

bash 复制代码
# 1. 停止 Docker 服务(避免占用)
sudo systemctl stop docker

# 2. 修改配置文件,添加镜像源
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",
	"https://docker.xuanyuan.me",
	"https://mirror.ccs.tencentyun.com",
	"https://mirror.huaweicloud.com",
	"https://docker.1ms.run"
    ]
}
EOF

# 3. 重新加载系统配置,重启 Docker
sudo systemctl daemon-reload
sudo systemctl restart docker

# 4. 查看 Docker 信息
docker info
# 终端输出的Registry Mirrors就是配置好的镜像源
Client: Docker Engine - Community
 Version:    27.0.3
 Context:    default
 Debug Mode: false
...
...
...
 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/
  https://docker.xuanyuan.me/
  https://mirror.ccs.tencentyun.com/
  https://mirror.huaweicloud.com/
  https://docker.1ms.run/
 Live Restore Enabled: false
 
# 5. 重新运行docker run hello-world
docker run hello-world
# 如果一切顺利,会输出以下信息
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete 
Digest: sha256:f7931603f70e13dbd844253370742c4fc4202d290c80442b2e68706d8f33ce26
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/
相关推荐
python百炼成钢1 分钟前
54.Linux IIO驱动框架
linux·运维·服务器·驱动开发
纷飞梦雪3 分钟前
ubuntu22开启root
linux·运维·ubuntu
Konwledging4 分钟前
linux debug工具集合
linux
星哥说事4 分钟前
恶意团伙利用 PHP-FPM 未授权访问漏洞发起大规模攻击
linux·服务器
Evan芙5 分钟前
shell编程求10个随机数的最大值与最小值
java·linux·前端·javascript·网络
再睡一夏就好12 分钟前
进程调度毫秒之争:详解Linux O(1)调度与进程切换
linux·运维·服务器·c++·算法·哈希算法
BS_Li31 分钟前
【Linux系统编程】库制作与原理
linux·运维·服务器
我真会写代码34 分钟前
从入门到精通:Java Socket 网络编程实战(含线程池优化)
java·linux·服务器·socket·tcp/ip协议
刘某的Cloud38 分钟前
全局禁用ipv6
linux·运维·网络·系统·ipv6
a***592639 分钟前
docker离线安装及部署各类中间件(x86系统架构)
docker·中间件·系统架构