简体   繁体   English

Docker Buildx 无法从本地提取继承图像

[英]Docker Buildx Cannot Pull From Local for Inherited Image

I have 2 Dockerfiles on my Host Machine ( Ubuntu 20.04 ).我的主机上有 2 个 Dockerfile( Ubuntu 20.04 )。 I am running docker-ce version Docker version 19.03.12, build 48a66213fe with Experimental Features enabled.我正在运行 docker-ce 版本 Docker 版本 19.03.12,构建 48a66213fe 并启用了实验功能。 I am able to build each of them with "docker buildx" for the ARM architecture and successfully run them on my embedded Linux ARM board.我能够为 ARM 架构使用“docker buildx”构建它们中的每一个,并在我的嵌入式 Linux ARM 板上成功运行它们。

Dockerfile 1: Dockerfile 1:

FROM python:3.8-slim-buster

COPY git /home/git

WORKDIR /home

RUN apt-get update -y && apt-get --no-install-recommends install build-essential pkg-config libzmq5 -y && \
    cd git && python3 setup.py install && apt remove --purge build-essential pkg-config -y && \
    apt auto-remove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

ADD publisher.py /home/publisher.py

Dockerfile 2: Dockerfile 2:

FROM python:3.8-slim-buster

COPY git /home/git

WORKDIR /home

RUN apt-get update -y && apt-get --no-install-recommends install build-essential pkg-config libzmq5 -y && \
    cd git && python3 setup.py install && apt remove --purge build-essential pkg-config -y && \
    apt auto-remove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

ADD subscriber.py /home/subscriber.py

Build process to create ARM compatible image on Host:在主机上创建 ARM 兼容映像的构建过程:

docker buildx create --name builder || true
docker buildx use builder
docker buildx build --platform linux/arm/v7 -t "company-publisher:v1.3" . --load
docker save company-publisher:v1.3 > company-publisher-v1.3.tar

Loading the image on the ARM:在 ARM 上加载图像:

docker load < ./company-publisher-v1.3.tar

The steps are same for the subsriber.订阅者的步骤相同。

Since the images are basically the same, I wanted to change the publisher Dockerfile to the following:由于图像基本相同,我想将发布者 Dockerfile 更改为以下内容:

FROM company-subscriber:v1.3

ADD publisher.py /home/publisher.py

Docker images shows that it is there locally: Docker 图像显示它在本地:

REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
company-subscriber          v1.3                d2002fa18a8d        9 hours ago         121MB

But I get the error shown below - It ALWAYS tries to pull from docker.io ( which obviously does not have the image I am trying to inherit from ):但我得到如下所示的错误 - 它总是试图从 docker.io 中提取(显然没有我试图继承的图像):

docker buildx build --platform linux/arm/v7 -t "company-publisher:v1.3" . --load
[+] Building 1.5s (5/6)                                                                                                                                                                                              
 => [internal] load .dockerignore                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                 0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                            0.0s
 => => transferring dockerfile: 104B                                                                                                                                                                            0.0s
 => ERROR [internal] load metadata for docker.io/library/company-subscriber:v1.3                                                                                                                               0.8s
 => [internal] load build context                                                                                                                                                                               0.0s
 => => transferring context: 34B                                                                                                                                                                                0.0s
 => ERROR [1/2] FROM docker.io/library/company-subscriber:v1.3                                                                                                                                                 0.7s
 => => resolve docker.io/library/company-subscriber:v1.3                                                                                                                                                       0.7s
------
 > [internal] load metadata for docker.io/library/company-subscriber:v1.3:
------
------
 > [1/2] FROM docker.io/library/company-subscriber:v1.3:
------
failed to solve: rpc error: code = Unknown desc = failed to load cache key: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed

How can I get buildx to work with a local image?如何让 buildx 使用本地映像? Thanks.谢谢。

There are a few different buildx drivers , and they each have tradeoffs.有几个不同的 buildx 驱动程序,它们都有权衡。

First is the docker driver.首先是docker驱动程序。 This is the driver for the default builder instance if you change nothing else.如果您不进行任何更改,这是默认构建器实例的驱动程序。 It's build-in to to the docker engine and should have visibility to the other images on the host.它内置在 docker 引擎中,应该可以看到主机上的其他图像。 The goal is to be similar to the classic build process.目标是类似于经典的构建过程。

The second is docker-container and is the default if you create a new builder instance with docker buildx create .第二个是docker-container如果您使用docker buildx create创建一个新的构建器实例,则它是默认值。 This is needed for specific functionality like the multi-platform images and exporting the cache.这是多平台图像和导出缓存等特定功能所必需的。 But since it's running inside a container, you won't see the other images on the docker host.但由于它在容器内运行,您不会在 docker 主机上看到其他图像。


One big issue when trying to use the docker host for multi-architecture images is that the docker engine itself doesn't support multi-architecture images.尝试将 docker 主机用于多架构映像时,一个大问题是 docker 引擎本身不支持多架构映像。 It will only pull one of the architectures from a registry, so your image becomes a single architecture that likely can't be used in a multi-architecture build.它只会从注册表中提取其中一个架构,因此您的映像变成了一个可能无法在多架构构建中使用的单一架构。

The easiest fix is to use a registry for your images.最简单的解决方法是为您的图像使用注册表。 This supports the multi-architecture image formats which you can't do on a docker host.这支持在 docker 主机上无法实现的多架构图像格式。 And this is portable when you run the build on another node.当您在另一个节点上运行构建时,这是可移植的。

There are other options in the buildx documentation to cache from/to other locations. buildx 文档中还有其他选项可以从/到其他位置进行缓存。 But when dealing with a multi-arch base image, you'll find the external registry is much easier, and likely the one that actually works.但是在处理多架构基础映像时,您会发现外部注册表要容易得多,而且很可能是实际工作的那个。 Keep in mind this doesn't have to be Docker Hub, you can run you own registry server on the same host where you run your builds.请记住,这不一定是 Docker 集线器,您可以在运行构建的同一主机上运行自己的注册表服务器。


Side note: buildx/buildkit also benefits from having a persistent volume if you happen to run ephemeral builders (eg using some kind of DinD on a CI server).旁注:如果您碰巧运行临时构建器(例如在 CI 服务器上使用某种 DinD),buildx/buildkit 也受益于持久卷。 Buildkit can be configured to automatically garbage collect this cache to avoid the storage problems of the past. Buildkit 可以配置为自动垃圾收集这个缓存,以避免过去的存储问题。 And with that cache, you avoid the need to download the image layers on every build from the external registry.使用该缓存,您无需在每次构建时从外部注册表下载图像层。

use docker login command and then provide user login account detail once login success then try again docker build command It will work.使用 docker 登录命令,然后在登录成功后提供用户登录帐户详细信息,然后重试 docker 构建命令它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM