Ubuntu26.04之Docker配置国内镜像加速器

📝 错误信息

bash 复制代码
moshow@moshow-ubuntu:~/Downloads$ 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": read tcp [2409:8a55:1095:20d1:219b:967a:aa98:a2b4]:32974->[2600:1f18:2148:bc01:d1d6:a87:e7fa:b2d7]:443: read: connection reset by peer

Run 'docker run --help' for more information

网络连接被远端服务器重置了(read: connection reset by peer),这在国内访问 Docker Hub 拉取镜像时很常见。核心的解决方法就是配置国内镜像加速器。

🚀 解决方法:配置国内镜像加速器

bash 复制代码
# -----------------------------------------------------
# - 🚀 Powered by Moshow郑锴
# - 🌟 Might the holy code be with you!
# -----------------------------------------------------
# 🔍 公众号 👉 软件开发大百科
# 💻 CSDN 👉 https://zhengkai.blog.csdn.net
# 📂 Github 👉 https://github.com/moshowgame

这个配置只需要修改一个文件,操作很简单。

第一步:创建或修改配置文件

在终端中执行以下命令,这会自动创建 /etc/docker/daemon.json 文件并写入推荐的镜像源地址:

bash 复制代码
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": [
    "https://docker.xuanyuan.me",
    "https://docker.1ms.run",
    "https://docker.m.daocloud.io"
  ]
}
EOF

为什么要配置多个地址? Docker 会按顺序尝试,如果一个镜像源暂时不可用,会自动切换到下一个,提高拉取成功率。

第二步:重启 Docker 服务

配置修改后,需要重启 Docker 才能生效:

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

第三步:验证配置是否生效

运行下面的命令,在输出的信息里找到 Registry Mirrors 部分,确认包含你刚刚配置的地址,就说明成功了。

bash 复制代码
docker info | grep -A 5 "Registry Mirrors"

✅ 验证结果

配置并重启 Docker 后,再试一次拉取 hello-world

bash 复制代码
docker run hello-world

这次应该就能成功拉取并运行了。

相关推荐
GGG7661 小时前
k8s-Pod Scheduler
云原生·容器·kubernetes
GGG7662 小时前
k8s-动态卷供应
云原生·容器·kubernetes
yunwei373 小时前
eBPF 教程:使用 fsession 追踪慢速 vfs_read 调用
linux·云原生
Henry-SAP19 小时前
SAP S/4HANA引领物流ERP新生态
人工智能·云原生·sap·erp
这个DBA有点耶19 小时前
从DBA到数据架构师(五):数据架构演进中的技术债务管理
数据库·程序人生·云原生·架构·dba·数据库管理员
霸道流氓气质1 天前
微服务架构中多实例消息抢占问题:技术解析与解决方案
微服务·云原生·架构
AAA@峥1 天前
K8s 资源管控:ResourceQuota 与 LimitRange 机制详解与实战
云原生·容器·kubernetes
云烟成雨TD1 天前
Micrometer 系列【63】统一观测:基于 Spring Boot 的生产级演示案例 | 基于 OTLP 集成 Prometheus + Jaeger
spring boot·云原生·prometheus
猫吃了源码1 天前
CentOS7使用Kubeadm安装部署K8s(Kubernetes)最新稳定版本1.26.x
云原生·容器·kubernetes
骇客野人1 天前
基于Nginx+Eureka+Apollo+Jenkins+SpringBoot Web系统分布式部署方案
nginx·eureka·jenkins