docker配置镜像加速但还是拉不下来的问题

求佬赐教

我配置了镜像加速器,但好像没有生效

[root@k8s-master01 ~]# docker --version
Docker version 28.4.0, build d8eb465
[root@k8s-master01 ~]# cat /etc/docker/daemon.json 
{
  "registry-mirrors": ["https://registry.***.com"]
}
[root@k8s-master01 ~]# systemctl restart docker

然后我尝试pull失败,好像没有用配置的mirror,

[root@k8s-master01 ~]# docker pull nginx:stable
Error response from daemon: Get "https://registry-1.docker.io/v2/": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

[root@k8s-master01 ~]# docker info | grep -A1 "Registry Mirrors:"
 Registry Mirrors:
  https://registry.**.com/

但是我使用完整的镜像地址是ok的

[root@k8s-master01 ~]# docker pull registry.**.com/library/nginx:stable
stable: Pulling from library/nginx
d107e437f729: Pull complete 
1b0ead710ba9: Pull complete 
630af9f1fcb8: Pull complete 
7ca080409cf1: Pull complete 
c04f61b76b4d: Pull complete 
87cc7677affb: Pull complete 
0c740d5dc502: Pull complete 
Digest: sha256:2945a0bfa07bf1d3cb9ba5f03678e2827f11c240e4c9d38e075037938310062a
Status: Downloaded newer image for registry.**.com/library/nginx:stable
registry.**.com/library/nginx:stable
1 个赞

不要改文件了,给镜像前面加东西,南京大学 ghcr.nju.edu.cn/

2 个赞

这个好用吗?一直找不到好用的

我不知道佬用的***是什么,但是我用的这个没问题
"registry-mirrors": ["https://registry.cyou"]
修改后要严格按照这个顺序重启加载docker 配置

systemctl stop docker
systemctl stop docker.socket
systemctl daemon-reload
systemctl start docker
systemctl start docker.socket

最后应该看到docker info的结果最后几行是这样的

 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Registry Mirrors:
  https://registry.cyou/
 Live Restore Enabled: false

还是直接使用一键脚本吧,
bash <(curl -sSL https://linuxmirrors.cn/docker.sh)

1 个赞

第一反应:这镜像站八成是“假加速”——daemon.json 里看着生效,其实 pull 的时候 docker 根本没走它,直接裸连 docker.io 超时了。

docker info 看你的 registry mirrors 是否生效

巧了,和你遇到了同样的问题。配置了死活生效不了,最后还是选择前面加网址了

前面加网址就行了,如果一些脚本有影响,就重新tag一下就行。

因为有些镜像加速的代码写的有问题,所以对于 nginx 这种官方镜像会无法通过配置文件走镜像加速只能通过加前缀,而代码没问题的就可以正常处理这种镜像。之前自建镜像加速的 CF 脚本刚出那阵出现过这种问题,后续就修复了,可能你用的这个一直没更新或者自己写的有 bug。

直接用梯子吧 省事多了

大概率是因为你的https://registry.***.com不行,换个能用的

https://registry.***.com

还有***.com的网站吗?

还有可能是docker有缓存,配置了镜像地址没生效,需要清理一下缓存

可能是镜像站挂了,去年的9月(好像是)之后,很多镜像站都挂了,但是搜到的一些教程可能还是在那之前的,直接照着配就会出问题