执行 Docker buildx build 时报 401 Unauthorized 错误的解决办法

问题描述

今天编译新的镜像时突然出现如下错误信息

➜  custom git:(master) docker buildx build --platform linux/amd64,linux/arm64 -t chihpengkao/nextcloud:latest -t chihpengkao/nextcloud:v2022.06.22 --push .
[+] Building 1.8s (5/5) FINISHED                                                                                                                                                                  
 => [internal] load .dockerignore                                                                                                                                                            0.0s
 => => transferring context: 2B                                                                                                                                                              0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                         0.0s
 => => transferring dockerfile: 1.78kB                                                                                                                                                       0.0s
 => ERROR [linux/arm64 internal] load metadata for docker.io/library/nextcloud:apache                                                                                                        1.8s
 => CANCELED [linux/amd64 internal] load metadata for docker.io/library/nextcloud:apache                                                                                                     1.8s
 => [auth] library/nextcloud:pull token for registry-1.docker.io                                                                                                                             0.0s
------
 > [linux/arm64 internal] load metadata for docker.io/library/nextcloud:apache:
------
Dockerfile:1
--------------------
   1 | >>> FROM nextcloud:apache
   2 |     
   3 |     RUN set -ex; \
--------------------
error: failed to solve: failed to fetch oauth token: unexpected status: 401 Unauthorized

解决方案

看起来应该是身份令牌过期了,重新使用 Docker Hub 的账户登录

docker login -u 账户名

再次执行编译,恢复正常

➜  custom git:(master) docker login -u chihpengkao                      
Password: 
WARNING! Your password will be stored unencrypted in /home/martincz/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
➜  custom git:(master) docker buildx build --platform linux/amd64,linux/arm64 -t chihpengkao/nextcloud:latest -t chihpengkao/nextcloud:v2022.06.22 --push .
[+] Building 10.7s (11/20)                                                                                                                                                                                                                   
 => [internal] load build definition from Dockerfile                                                                                                                                                                                    0.0s
 => => transferring dockerfile: 1.78kB                                                                                                                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                       0.0s
 => => transferring context: 2B                                                                                                                                                                                                         0.0s
 => [linux/arm64 internal] load metadata for docker.io/library/nextcloud:apache                                                                                                                                                         6.5s
 => [linux/amd64 internal] load metadata for docker.io/library/nextcloud:apache                                                                                                                                                         5.8s
 => [auth] library/nextcloud:pull token for registry-1.docker.io                                                                                                                                                                        0.0s
 => [internal] load build context                                                                                                                                                                                                       0.0s
 => => transferring context: 38B                                                                                                                                                                                                        0.0s
 => [linux/amd64 1/7] FROM docker.io/library/nextcloud:apache@sha256:b319922a34539cfe7894000e635318634eb044b69e6c0182e8eea8957f3b42e9                                                                                                   0.0s
 => => resolve docker.io/library/nextcloud:apache@sha256:b319922a34539cfe7894000e635318634eb044b69e6c0182e8eea8957f3b42e9                                                                                                               0.0s
 => CACHED [linux/arm64 1/7] FROM docker.io/library/nextcloud:apache@sha256:b319922a34539cfe7894000e635318634eb044b69e6c0182e8eea8957f3b42e9                                                                                            0.0s
 => => resolve docker.io/library/nextcloud:apache@sha256:b319922a34539cfe7894000e635318634eb044b69e6c0182e8eea8957f3b42e9                                     
0 0 投票数
文章评分
订阅评论
提醒
0 评论
最旧
最新 最多投票
内联反馈
查看所有评论
By 马丁龙猪

标签

归档

其他操作