Bootstrap

docker x86环境构建arm镜像出现failed to fetch oauth token问题

问题:最近在使用x86的MAC机器准备打包arm的镜像时使用命令如下

docker buildx build --platform linux/arm64 --load --no-cache -t deepface:v1-arm .

出现连接问题

[+] Building 31.7s (3/3) FINISHED                                                           docker-container:mybuilder3
 => [internal] load build definition from Dockerfile                                                               0.0s
 => => transferring dockerfile: 3.01kB                                                                             0.0s
 => ERROR [internal] load metadata for docker.io/library/python:3.8.12                                            31.7s
 => [auth] library/python:pull token for registry-1.docker.io                                                      0.0s
------
 > [internal] load metadata for docker.io/library/python:3.8.12:
------
Dockerfile:2
--------------------
   1 |     # base image
   2 | >>> FROM python:3.8.12
   3 |     LABEL org.opencontainers.image.source https://github.com/serengil/deepface
   4 |
--------------------
ERROR: failed to solve: DeadlineExceeded: DeadlineExceeded: DeadlineExceeded: python:3.8.12: failed to resolve source metadata for docker.io/library/python:3.8.12: failed to authorize: DeadlineExceeded: failed to fetch oauth token: Post "https://auth.docker.io/token": dial tcp 185.45.7.189:443: i/o timeout

一直报错连不上https://auth.docker.io/token

在网上找了各自解决方式,试了换镜像源、配置DNS、切换代理等等方式都是不行,但是我用docker build就没问题,想着这两之间构建的环境是一样的吗?问了下chatgpt给出的答案也很模糊,但是明确问题应该就是docker buildxdocker build环境是不一样的,所以使用的docker login应该也不一样,
在使用 docker buildx之前我们都需要

docker buildx create --name mybuilder
docker buildx use mybuilder

这里使用了mybuilder环境,构建了新的 Buildx builder 实例后好像和默认的就不一致了,所以我切换到默认的环境

--看下有哪些
docker buildx ls
--切换到默认
docker context use default
docker buildx use default

然后在执行docker buildx就可以访问到认证信息,开始构建了。

;