docker image pull时频繁出现unauthorized: authentication required问题的一种解决方法

问题现象如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@ci1 ~]# docker image pull wzkres/centos-ci-gcc:centos-7-cross-arm64
centos-7-cross-arm64: Pulling from wzkres/centos-ci-gcc
2d473b07cdd5: Already exists
9d26d6802cad: Pull complete
90f6d29b7c1a: Pull complete
7bfff1b24796: Pull complete
80b3d4546432: Pull complete
c3a37398e8b3: Pull complete
3ba42b3a770d: Pull complete
85b3405c69c4: Downloading
2ad9c2d42a3d: Waiting
5f1b06925eb4: Waiting
4f4fb700ef54: Waiting
57c257cf6173: Waiting
787f48d693d2: Waiting
9f1677804e77: Waiting
c13fd6dc43b4: Waiting
80bd40938514: Waiting
56ba96a89fa8: Waiting
unauthorized: authentication required

在从hub.docker.com拉取公开镜像时,频繁出现标题中提到的错误而失败,出现时间随机,且出现频率非常高,导致稍大些的镜像几乎无法顺利完成下载。一开始以为是网络问题,各种更换“科学”,使用镜像代理均没什么效果,看提示的是“authentication”,还以为是docker hub登录信息的问题,于是也试过docker login -u xxxx,无果…

后来在搜索时发现了这个github issue(https://github.com/docker/hub-feedback/issues/1484)中有位大佬提到的“clock-drift”,于是检查了下系统时间,发现果然比当前时间慢了5分钟左右,进一步检查发现不知为何ntp是inactive状态(CentOS 8),于是执行:

1
2
3
4
5
6
7
8
9
[root@ci1 ~]# timedatectl set-ntp yes
[root@ci1 ~]# timedatectl
               Local time: 四 2025-02-13 23:18:58 CST
           Universal time: 四 2025-02-13 15:18:58 UTC
                 RTC time: 四 2025-02-13 15:18:58
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

可以看到synchronized变为yes,系统时间也重新校准了,再次docker pull,就没再出现过authentication required,虽然慢了点,但最后还是成功pull到了,记录下,供遇到同样问题的朋友们参考。

博主友情提示:

如您在评论中需要提及如QQ号、电子邮件地址或其他隐私敏感信息,欢迎使用>>博主专用加密工具v3<<处理后发布,原文只有博主可以看到。