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

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

相关推荐
野熊佩骑2 小时前
Kubernetes实战系列文章(三) 之 K8S运维常用命令
linux·运维·docker·微服务·云原生·容器·kubernetes
DolitD5 小时前
实时云渲染多应用并发:CELL容器技术突破3D隔离瓶颈
云原生·容器·实时互动·图形渲染·数据可视化
鹤落晴春5 小时前
【K8s】Kustomize管理
云原生·容器·kubernetes
bruce1288 小时前
K8s Pod 异常重启排查
云原生·容器·kubernetes
MetaLite8 小时前
微服务认证选型-SpringSecurity-SaToken与自研方案
微服务·云原生·架构
运维老郭11 小时前
Prometheus 监控 K8s 从入门到入坑:工作原理 + 部署实操 + 避坑指南
云原生·容器·kubernetes
AAA@峥11 小时前
从零搭建 Prometheus 完整监控告警体系|Linux 部署 + node_exporter+Grafana 可视化
云原生·grafana·prometheus
10mAh13 小时前
【Docker】磁盘空间被占满怎么清理?——overlay2、容器日志与 Build Cache 排查实战
docker·容器·eureka
SelectDB技术团队14 小时前
Apache Doris 多云原生实践:SaaS、BYOC 与四大公有云覆盖
数据库·阿里云·云原生·华为云·腾讯云·亚马逊云·写入更新
鹤落晴春1 天前
有状态应用 vs 无状态应用
运维·云原生·k8s