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/
相关推荐
江畔柳前堤5 分钟前
第13章:docker生产环境部署实战
运维·git·docker·容器·代码复审
iCxhust15 分钟前
linux目录是否保存在硬盘 启动后读入解析的
linux·运维·服务器
懒鸟一枚15 分钟前
Linux 系统 Service 服务配置详解
linux·服务器·网络
RisunJan1 小时前
Linux命令-readonly(Bash 内建设置只读变量)
linux
FlightYe2 小时前
FFmpeg移动端硬解机制
linux·网络·ffmpeg·音视频·实时音视频·视频编解码
笨笨没好名字2 小时前
Leetcode刷题python3版第一周(下)
linux·算法·leetcode
hj2862513 小时前
Docker 容器化技术标准化笔记
java·笔记·docker
潘正翔3 小时前
docker基础_镜像使用
linux·运维·服务器·docker·容器·centos·devops
24计网1王仔寿3 小时前
Linux运维与云计算全栈系统化学习指南(Shell+虚拟化+OpenStack+Docker+公私云实战)
linux·课程设计·数据库开发·微信公众平台·neo4j·命令模式·sequoiadb
江湖有缘3 小时前
Lunalytics部署指南:使用Docker快速搭建私有监控面板
运维·docker·容器