Docker连接超时的解决方法

使用docker pull命令下载镜像时,可能因网络问题导致超时,报错如下:

复制代码
Error response from daemon: Get "https://registry-1.docker.io/v2/": context deadline exceeded

针对该问题,最有效的解决方法之一,就是配置国内镜像加速器,流程如下。
1. 更改镜像源

打开文件/etc/docker/daemon.json。如果使用snap安装Docker,则打开文件/var/snap/docker/current/config/daemon.json

输入可用的镜像源:

复制代码
{
  "registry-mirrors": [
    "https://dockerhub.icu",
    "https://docker.chenby.cn",
    "https://docker.1panel.live",
    "https://docker.awsl9527.cn",
    "https://docker.anyhub.us.kg",
    "https://dhub.kubesre.xyz"
  ]
}

上述镜像源 [ 1 ] ^{[1]} [1]仅作示例,目前暂时可用。如果不可用,则换用其它镜像源。

2. 重启Docker

bash 复制代码
sudo systemctl daemon-reload
sudo systemctl restart docker

如果使用snap安装Docker,则运行如下命令:

bash 复制代码
sudo systemctl daemon-reload
sudo snap restart docker

3. 验证

运行命令

bash 复制代码
sudo docker info

如果终端显示了添加的镜像源,则表明更改的镜像源已生效。显示的部分信息如下:

复制代码
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Registry Mirrors:
  https://dockerhub.icu/
  https://docker.chenby.cn/
  https://docker.1panel.live/
  https://docker.awsl9527.cn/
  https://docker.anyhub.us.kg/
  https://dhub.kubesre.xyz/
  https://huecker.io/
  https://dockerhub.timeweb.cloud/
  https://noohub.ru/
  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 pull命令下载镜像。下载成功后,使用docker images命令查看本地的镜像。

参考文献

1\] [docker镜像源(可用)](https://zhuanlan.zhihu.com/p/712926329) \[2\] [Docker连接超时?5种方法快速解决](https://blog.csdn.net/haohaizi_liu/article/details/149633347) \[3\] [Docker简单介绍与使用以及下载对应镜像(项目前置)](https://blog.csdn.net/weixin_75111785/article/details/148810222) \[4\] [从Docker拉取镜像一直失败超时?这些解决方案帮你解决烦恼](https://blog.csdn.net/weixin_50160384/article/details/139861337)

相关推荐
hjxu201616 小时前
【OpenClaw 龙虾养成笔记一】在远程服务器,使用Docker安装OpenClaw
服务器·笔记·docker
Stewie1213818 小时前
Docker 面试题
运维·docker·容器
vpk11219 小时前
Docker Compose 安装 Redis
redis·docker·容器
last demo21 小时前
Docker-compose和图形界面管理
docker·容器·eureka
好像不对劲1 天前
【docker】win10 wsl docker不能挂GPU
运维·docker·容器·wsl
江畔何人初1 天前
Docker、containerd、CRI、shim 之间的关系
运维·docker·云原生·容器·kubernetes
杨浦老苏1 天前
在线视频播放器YT-DLP Web Player
docker·工具·群晖·下载·多媒体
ALex_zry1 天前
Docker Compose 配置文件完全指南:从基础到生产级安全实践
服务器·安全·docker
万象.1 天前
docker镜像仓库
运维·docker·容器
姚不倒1 天前
Docker 核心原理与运维实战:从入门到生产级理解
运维·docker·架构