Docker 入门:警告:所请求的镜像平台 (linux/arm64/v8) 与检测到的主机平台 (linux/amd64) 不匹配。

21

我正在从官方Docker网站开始进行“入门指南”。在第四部分“共享应用程序”中,当我尝试从play-with-docker.com运行我的镜像时,遇到了这个错误信息。

WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested

我使用我的苹果M1笔记本电脑构建了这个镜像:

FROM node:12-alpine
# Adding build tools to make yarn install work on Apple silicon / arm64 machines
RUN apk add --no-cache python2 g++ make
WORKDIR /app
COPY . .
RUN yarn install --producti
CMD ["node", "src/index.js"]

我正在使用arm osx做同样的教程。我遇到了相同的错误。可惜play with docker网站没有任何方法来托管arm镜像。 - netskink
2个回答

26

如果您想在 linux/amd64 平台上运行镜像,您需要为该平台构建镜像。您可以使用 docker buildx 来完成,这样您就可以指定两个平台。

docker buildx build --platform linux/amd64,linux/arm64 -t <tag> .

1
我们在使用运行命令时需要用到什么? - withoutOne
1
请注意,如果在运行此命令时出现“WARNING: No output specified for docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load”等错误,则可以通过立即将镜像推送到Dockerhub来解决该问题:“docker buildx build --push --platform linux/amd64,linux/arm64 -t <tag> .”。 - awwsmm
2
我遇到了以下错误:ERROR: multiple platforms feature is currently not supported for docker driver. Please switch to a different driver (eg. "docker buildx create --use")。我该如何解决? - Wang
2
@wang执行建议的命令 docker buildx create --use。之后,使用我回答中提供的命令。 - netskink
之后,对于我来说,buildx build 命令失败了,并显示 "failed to solve: failed to read dockerfile: open /tmp/buildkit-mount544735555/Dockerfile: no such file or directory"。 - And Finally
这里有一些解释:https://devblogs.microsoft.com/azure-sql/development-with-sql-in-containers-on-macos/ - Campinho

2

我遇到了和srevinu相同的错误,因为我也使用了指向使用docker playground的教程。

这个序列将构建并推送到docker hub,以便在docker playground上运行。

  1. 在您的基于osx arm的计算机上 docker buildx build --platform linux/amd64,linux/arm64 -t <YOUR_DOCKERHUB_ID/getting-started --push .

(如果它给出了一个关于发出docker buildx create --use命令的错误和建议,请原样输入该命令.)

在docker hub的tags窗格中执行此命令后,您应该看到两个平台的镜像列表。一个是用于linux/amd64的镜像,另一个是用于linux/arm64的镜像。

enter image description here

  1. 在实例的Docker Playground中,运行以下命令:docker run -dp 3000:3000 --platform linux/amd64 johndavis940/getting-started

该镜像将会运行,并且端口图标将会是可用状态。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接