Ubuntu系统docker错误,failed to do request: Head "https://registry-1.docker.io/v2/...

78 阅读1分钟

我的Ubuntu系统的版本是24.04.3 LTS‌(代号Noble Numbat)。
今天通过参考官网Install Docker Engine on Ubuntu安装docker。在最后验证安装是否成功这一步是发生了错误。官网要求运行hello-world镜像sudo docker run hello-world

ubuntu@VM-0-11-ubuntu:/var/docker-install$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: failed to resolve reference "docker.io/library/hello-world:latest": failed to do request: Head "https://registry-1.docker.io/v2/library/hello-world/manifests/latest": dial tcp 108.160.170.44:443: connect: connection refused

解决办法:配置Docker镜像源

  1. 修改docker配置文件。
    打开终端,使用文本编辑器编辑Docker配置文件。
sudo nano /etc/docker/daemon.json

将以下内容添加到配置文件中:

{ 
  "registry-mirrors" : [ 
    "https://docker.m.daocloud.io", 
    "https://docker-cf.registry.cyou",
    "https://registry.docker-cn.com.mirror.aliyuncs.com/"
  ], 
  "insecure-registries" : [ 
    "docker.mirrors.ustc.edu.cn" 
  ], 
  "debug": true, 
  "experimental": false 
}

保存并退出文件。 2. 重启docker服务。 执行以下命令重启docker服务。

sudo systemctl restart docker

3. 验证配置 通过以下命令验证配置是否生效。

sudo docker info

确保 Registry Mirrors 显示你配置的镜像源。

  1. 运行hello-world镜像。
    执行命令sudo docker run hello-world

image.png