针对 docker 被墙无法pull,配置可用的镜像地址
2023.6.18之后发现 docker pull
无法拉去镜像,经测试常用的国内镜像地址已经不可用,如:Docker中国区官方、清华、中科技大学、163、华为、部分阿里等
可用镜像如下
https://docker.m.daocloud.io 道客云
https://docker.1ms.run 1ms
https://docker.1panel.live 1panel
https://docker.xuanyuan.me 轩辕
https://hub.rat.dev rat
使用方法
编辑或新建/etc/docker/daemon.json
文件,向其中添加registry-mirrors
项,使最终配置类似:
{
"registry-mirrors": ["https://dockerhub.icu"]
}
修改后重载守护进程
systemctl daemon-reload
systemctl restart docker
自动测试脚本
贴上一段docker镜像源是否有效的测试脚本
效果如下:

复制代码保存为 test.sh
,修改要测试的docker镜像源列表 mirrors 变量,运行即可
#!/bin/bash
# 检查必要命令是否存在
check_commands() {
local missing=()
for cmd in docker sed grep awk; do
if ! command -v $cmd &> /dev/null; then
missing+=("$cmd")
fi
done
if [ ${#missing[@]} -gt 0 ]; then
echo "错误: 缺少必要的命令 - ${missing[*]}"
exit 1
fi
}
# 测试单个镜像源
test_mirror() {
local url="$1"
local name="$2"
local test_image="library/hello-world:latest"
uri=$(echo "$url" | sed 's/^http[s]*:\/\///')
# echo "--> 拉取镜像地址: $uri/$test_image"
# 测试镜像拉取
local start_time=$(date +%s%3N)
if docker pull --quiet "$uri/$test_image" > /dev/null 2>&1; then
local end_time=$(date +%s%3N)
local duration=$((end_time - start_time))
echo -e "[\e[32m成功\e[0m] $name ($url) \e[33m<${duration}ms>\e[0m"
return 0
else
echo -e "[\e[31m失败\e[0m] $name ($url) \e[31m<拉取失败>\e[0m"
return 1
fi
}
# 主函数
main() {
check_commands
# 镜像源列表 (名称|地址)
local mirrors=(
"1毫秒|https://docker.1ms.run"
"1panel|https://docker.1panel.live"
"耗子面板|https://hub.rat.dev"
"轩辕镜像|https://docker.xuanyuan.me"
"doublezonline|https://doublezonline.cloud"
"Timeweb|https://dockerhub.timeweb.cloud"
"anyhub|https://docker.anyhub.us.kg"
)
echo "========================================"
echo " Docker镜像源可用性测试 by Jeeinn.com"
echo " 测试镜像: library/hello-world:latest"
echo "========================================"
# 测试所有镜像源
for mirror in "${mirrors[@]}"; do
local name=$(echo "$mirror" | awk -F'|' '{print $1}')
local url=$(echo "$mirror" | awk -F'|' '{print $2}')
test_mirror "$url" "$name"
done
echo "========================================"
echo -e "测试完成!建议选择[\e[32m成功\e[0m]且耗时最短的镜像源"
}
main
参考:
https://gist.github.com/y0ngb1n/7e8f16af3242c7815e7ca2f0833d3ea6
https://www.v2ex.com/t/949738#r_13235392
https://linux.do/t/topic/114516
一个监控可用docker镜像源的网站
https://status.1panel.top/status/docker