DockerHub 镜像加速配置指南(Windows、Mac、Linux)
DockerHub 镜像加速配置指南涵盖 Windows、Mac、Linux 环境。提供多个国内可用镜像源清单,详解 Docker Daemon、Containerd 及 BuildKit 的 registry-mirrors 配置方法。包含多源回退策略、批量测速脚本、常见问题解答及安全合规建议,解决镜像拉取慢、429 错误等问题。

DockerHub 镜像加速配置指南涵盖 Windows、Mac、Linux 环境。提供多个国内可用镜像源清单,详解 Docker Daemon、Containerd 及 BuildKit 的 registry-mirrors 配置方法。包含多源回退策略、批量测速脚本、常见问题解答及安全合规建议,解决镜像拉取慢、429 错误等问题。

适用对象:国内云服务器/办公网络拉取 DockerHub 镜像慢、易触发限速(429/Too Many Requests)的场景 用途:一键配置镜像加速、按需切换备用源、排障与测速 安全提示:第三方镜像源非官方服务,不建议用于私有/机密镜像的拉取与推送
优先推荐(作者实测口碑好、稳定性优先)
其他可选(用户提供状态:正常;建议与上方推荐源搭配做备份)
说明:上述大多为 DockerHub 反向代理/镜像加速端点,供
docker.io拉取加速使用。不要加尾部斜杠(例如使用https://docker.1ms.run,而非https://docker.1ms.run/)。任何第三方源都可能随时间变化,建议至少配置 2~3 个镜像并保留官方回源作为兜底。
将配置替换/合并为(按需增减镜像源):
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker-0.unsee.tech",
"https://docker.m.daocloud.io"
],
"features": {
"buildkit": true
}
}
验证:终端执行 docker info | findstr /i "Registry Mirrors"(Win)或 docker info | grep -A 3 "Registry Mirrors"(macOS/Linux),拉取测试:docker pull hello-world 或 docker pull busybox:latest。
Rootless Docker(如用 dockerd-rootless-setuptool.sh 安装):将同样的 JSON 放到 ~/.config/docker/daemon.json,然后:
systemctl --user daemon-reload
systemctl --user restart docker
重载并重启:
sudo systemctl daemon-reload
sudo systemctl restart docker
创建/编辑 /etc/docker/daemon.json:
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker-0.unsee.tech",
"https://docker.m.daocloud.io"
],
"live-restore": true,
"features": {
"buildkit": true
}
}
许多发行版/平台(如 k3s)默认用 containerd,需在其层面配置镜像加速。
crictl pull docker.io/library/busybox:latestnerdctl --namespace k8s.io pull docker.io/library/busybox:latest重启:
sudo systemctl restart containerd
在 /etc/containerd/config.toml 中找到(或新增)以下段落,并替换为:
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://docker.1ms.run", "https://docker-0.unsee.tech", "https://registry-1.docker.io"]
若没有配置文件,先生成默认模板:
sudo mkdir -p /etc/containerd
containerd config default | sudo tee /etc/containerd/config.toml >/dev/null
对纯 BuildKit 环境(CI/CD 常见),在 BuildKit 层配置镜像最有效。
/etc/buildkit/buildkitd.toml:
[registry."docker.io"]
mirrors = ["https://docker.1ms.run", "https://docker-0.unsee.tech"]
重启:sudo systemctl restart buildkit(或按你的 Supervisor 重启)。
daemon.json/config.toml 里配置 registry-mirrors / endpoint 后,你仍然使用原始名称拉取:docker pull docker.io/library/nginx:alpine
Docker 会自动优先走镜像源,失败再回源官方。
docker pull docker.1ms.run/library/nginx:alpine
注意:不同镜像站的路径规则可能略有差异,通常 library/ 前缀仍需保留。
https://registry-1.docker.io,避免'全部超时'导致业务不可用。insecure-registries。docker login 使用自己的 DockerHub 账号以抑制匿名限速(不要把凭据交给第三方域名)。Q1:配置后还是慢/报错(TLS/证书/握手失败)?
sudo apt-get install --reinstall ca-certificates 或等价命令。Q2:提示 Too Many Requests / 429?
docker login 使用个人账号拉取(仍建议只拉公共镜像)。Q3:Kubernetes 节点也需要加速?
/etc/containerd/config.toml 配置同样的 mirrors,然后滚动重启节点的 containerd/kubelet。Q4:如何确认加速生效?
docker info 能看到 Registry Mirrors 列表。time docker pull busybox:latest 对比前后时延(首次拉取最具参考意义)。说明:该脚本通过访问
/v2/和试拉busybox:latest的 manifest 来做'轻量连通/响应'检测,不会大规模下载层文件;实际速度仍受网络波动与镜像站后端缓存影响。
#!/usr/bin/env bash
set -euo pipefail
MIRRORS=(
"https://docker.1ms.run"
"https://docker-0.unsee.tech"
"https://docker.m.daocloud.io"
"https://ccr.ccs.tencentyun.com"
"https://hub.xdark.top"
"https://dhub.kubesre.xyz"
"https://docker.kejilion.pro"
"https://docker.xuanyuan.me"
"https://docker.hlmirror.com"
"https://run-docker.cn"
"https://docker.sunzishaokao.com"
"https://image.cloudlayer.icu"
"https://docker.tbedu.top"
"https://hub.crdz.gq"
"https://docker.melikeme.cn"
)
printf "%-34s %-10s %-s\n" "MIRROR" "V2(ms)" "NOTES"
for m in "${MIRRORS[@]}"; do
t=$(curl -o /dev/null -s -w "%{time_total}" "${m}/v2/" || echo "fail")
note=""
if [ "$t" == "fail" ]; then
note="connect error"
else
# 取毫秒
t=$(awk -v n="$t" 'BEGIN{printf "%.0f", n*1000}')
printf "%-34s %-10s %-s\n" "$m" "$t" "$note"
fi
done
若你无权修改系统全局配置,也可把单个镜像站前缀写入镜像名测试:
docker pull docker.1ms.run/library/busybox:latest
docker info 是否显示了 Registry Mirrors 并且含你的新镜像源curl https://<mirror>/v2/ 是否返回 HTTP 200/401/403(能连通)https://registry-1.docker.io 兜底{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker-0.unsee.tech",
"https://docker.m.daocloud.io"
],
"features": {
"buildkit": true
}
}
[plugins."io.containerd.grpc.v1.cri".registry]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
endpoint = ["https://docker.1ms.run", "https://docker-0.unsee.tech", "https://registry-1.docker.io"]
{
"registry-mirrors": [
"https://docker.1ms.run",
"https://docker-0.unsee.tech",
"https://docker.m.daocloud.io"
],
"features": {
"buildkit": true
}
}

微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML转Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online
将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online