繁体   English   中英

错误:构建 Docker 图像时出现“无法使用前端 dockerfile.v0 解决:无法创建 LLB 定义:清单中的平台不匹配”

[英]Error: "Failed to solve with frontend dockerfile.v0: failed to create LLB definition: no match for platform in manifest" when building a Docker image

我收到错误:

无法使用前端 dockerfile.v0 解决:无法创建 LLB 定义:清单中的平台不匹配

构建以下 Dockerfile 时:

FROM mcr.microsoft.com/dotnet/framework/aspnet:4.8
COPY . /inetpub/wwwroot

原因很简单,我的 docker 桌面在 linux 容器上运行,并且图像是从 windows 图像构建的。

只需切换到 windows 容器即可解决问题。

该消息毫无头绪,因此我希望这可以为其他人节省一些时间。

在我的情况下,我使用带有m1处理器的 mac 来运行 python 图像,我的docker-composeDockerfile看起来像这样:

docker-compose.yml

version: '3.7'

services:
  words_bot:
    build: .
    restart: unless-stopped

Dockerfile:

FROM python:3-onbuild
COPY . /usr/src/app
CMD ["python", "-m", "bot"]

似乎图像期待x86主机架构,所以我得到了 OP 所指的错误。

在我将platform: linux/amd64添加到docker-compose.yml 之后,一切都开始按预期工作:

version: '3.7'

services:
  cng_words_bot:
    build: .
    platform: linux/amd64
    restart: unless-stopped

在 M1 上为我修复的 docker 文件中提供平台

例如FROM --platform=linux/amd64 amazonlinux:2018.03

Docker 与某些架构(例如 M1)混淆。 确保指定架构(平台)

  services:
      service-name:
        platform: linux/x86_64. # specify the architecture here
        image: some-image

在 macOS 上,使用英特尔芯片构建“标准”docker 图像,我遇到了这个问题。

重新启动 Docker 守护程序为我修复了它。

(Assuming you are running Docker in Windows platform) To resolve this issue, switch the container from Linux to Windows by right clicking on the Docker icon in the tray (we see this icon near the system clock after starting the Docker Engine) and select the选项“切换到 Windows 容器...”

步骤1
步骤1

第2步
第2步

在非常简单的 Dockerfile 上使用 docker 构建时,我自己偶然发现了类似的问题:

FROM node:lts-alpine

COPY ./ /app/
RUN cd /app && npm ci && npm run build

运行docker build -t foo. ,出现了原因略有不同的 OPs 错误。

但是,当运行docker pull node:lts-alpine ,然后重复该构建命令时,构建运行得很好。

恕我直言,对于 Windows,这看起来像是 Docker 中的一个小插曲。 切换到 Windows 容器似乎不是一个合理的选择,因为基本容器对于基于 Linux 的上下文非常有效。 无论如何都试图切换,但这只会为 Windows 带来 Docker 的不同错误。

对我来说,docker 图像本身没有构建。 所以我不得不添加--platform linux/x86_64作为docker build命令的参数。

就我而言。 我使用的是 Mac M1 ,它缺少一个/ ,如下所示:

它怎么样:

version: '3.6'
services:
  service-name:
    build:
      # It was without the /, like:
      context: .

固定的:

version: '3.6'
services:
  service-name:
    build:
      # The correct one
      context: ./

错误是:

failed to solve: rpc error: code = Unknown desc = failed to solve with frontend dockerfile.v0: failed to create LLB definition: unexpected status code [manifests latest]: 401 Unauthorized

而且我还需要更改 credsStore 值。 更多信息: docker pull gives error: no basic auth credentials #207

我希望它对某人有帮助,我花了很多时间才得到它。

搜索适用于您的硬件架构Docker 图像标签可以修复它。 例如,如果您使用的是Apple 芯片M1M2 ),则架构为 arm64。

见图片

在我的例子中,我只是与 wifi 断开连接,所以在花几个小时尝试调试问题之前仔细检查你是否在线!

暂无
暂无

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

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