英文:
docker build --platform=linux/amd64 fails: ERROR: failed to solve: no match for platform in manifest
问题
在Macbook M2机器上创建Docker构建时出现错误。这是可以复现错误的最简单示例:
echo "FROM alpine:latest" | docker build --platform=linux/amd64 --progress=plain -f - .
错误消息
请注意最后一行的错误:
#5 ERROR: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
------
> exporting to image:
------
ERROR: failed to solve: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
完整的错误输出
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 93B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/alpine:latest
#3 DONE 0.6s
#4 [1/1] FROM docker.io/library/alpine:latest@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11
#4 resolve docker.io/library/alpine:latest@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 0.0s done
#4 CACHED
#5 exporting to image
#5 exporting layers done
#5 exporting manifest sha256:c887664786a565506760c1ebb17d0edbbc0f8427a4e723d05bba6dc1c199f63f done
#5 exporting config sha256:c9eabdf343eb2fef6b265aa86db47ee270dd0a170bf37bef1dcf94fa73236b65 done
#5 exporting attestation manifest sha256:ff813dfd9ec5f193d95d20bafa96b3d48b7510d178d4ef3195981314151856f1 done
#5 exporting manifest list sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 naming to moby-dangling@sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 unpacking to moby-dangling@sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 ERROR: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
------
> exporting to image:
------
ERROR: failed to solve: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
然而,如果我执行以下任何一个命令,我可以轻松运行任何图像:
$ docker run --rm -ti --platform linux/amd64 alpine:latest uname -a
Linux b2a7299eadea 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 x86_64 Linux
$ docker run --rm -ti --platform linux/arm64 alpine:latest uname -a
Linux 00ecc31c7eeb 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 Linux
所以,如果我想要构建一个镜像,就会出现问题,但如果我尝试运行它,则没有问题。
故障排除:
- 我的机器是基于ARM的Apple M2处理器:
$ uname -a
Darwin 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:19 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6020 arm64
- 我知道Rosetta QEMU仿真可以工作,因为我可以运行以下命令:
$ docker run --rm -ti --platform linux/amd64 alpine:latest uname -m
x86_64
- Docker构建器已正确配置为多平台构建:
$ docker builder ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default * docker
default default running v0.11.6 linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64
desktop-linux docker
desktop-linux desktop-linux running v0.11.6 linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64
问题:
因此,问题是:如何使用docker build
并在本地保存Docker镜像?
英文:
On a Macbook M2 machine I am getting an error when creating a docker build.
This is the most boiled down example that can reproduce the error:
echo "FROM alpine:latest" | docker build --platform=linux/amd64 --progress=plain -f - .
error message
Notice the error in the last line:
#5 ERROR: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
------
> exporting to image:
------
ERROR: failed to solve: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
Full error output:
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 93B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/alpine:latest
#3 DONE 0.6s
#4 [1/1] FROM docker.io/library/alpine:latest@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11
#4 resolve docker.io/library/alpine:latest@sha256:02bb6f428431fbc2809c5d1b41eab5a68350194fb508869a33cb1af4444c9b11 0.0s done
#4 CACHED
#5 exporting to image
#5 exporting layers done
#5 exporting manifest sha256:c887664786a565506760c1ebb17d0edbbc0f8427a4e723d05bba6dc1c199f63f done
#5 exporting config sha256:c9eabdf343eb2fef6b265aa86db47ee270dd0a170bf37bef1dcf94fa73236b65 done
#5 exporting attestation manifest sha256:ff813dfd9ec5f193d95d20bafa96b3d48b7510d178d4ef3195981314151856f1 done
#5 exporting manifest list sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 naming to moby-dangling@sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 unpacking to moby-dangling@sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215 done
#5 ERROR: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
------
> exporting to image:
------
ERROR: failed to solve: no match for platform in manifest sha256:d9ab3e9e8a65da61fb54c3e2471c8fabf787ce49403919bff7eaf10f99e33215: not found
However, I can run any of the images easily if I do either:
$ docker run --rm -ti --platform linux/amd64 alpine:latest uname -a
Linux b2a7299eadea 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 x86_64 Linux
$ docker run --rm -ti --platform linux/arm64 alpine:latest uname -a
Linux 00ecc31c7eeb 5.15.49-linuxkit #1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022 aarch64 Linux
so there is a problem if I want to build an image, but no problem if I try to run it.
Troubleshooting:
- My machine is ARM-based apple M2 processor:
$ uname -a
Darwin 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:53:19 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6020 arm64
- I know that rosetta qemu emulation works, because I can run
$ docker run --rm -ti --platform linux/amd64 alpine:latest uname -m
x86_64
- docker builder is correctly configured for multiplatform builds:
$ docker builder ls
NAME/NODE DRIVER/ENDPOINT STATUS BUILDKIT PLATFORMS
default * docker
default default running v0.11.6 linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64
desktop-linux docker
desktop-linux desktop-linux running v0.11.6 linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64
question:
so the question is: How can I use docker build
and actually save a docker image locally?
答案1
得分: 13
你的错误应该与这个已打开的问题 https://github.com/moby/moby/issues/44578 有关,该问题已进入 Docker Desktop 4.20。
作为一种解决方法,你应该在 Docker Desktop 功能中禁用标志 Use containerd for pulling and storing images
来解决它。
你可以在 Docker Desktop 的设置中找到这个选项,即 "设置" > "正在开发的功能"。
英文:
Your error should be related to this open issue https://github.com/moby/moby/issues/44578 that enter into Docker Desktop 4.20.
As a workaround, you should disable the flag Use containerd for pulling and storing images
within the feature of Docker Desktop to solve it.
You find the setting Use containerd for pulling and storing images
in Docker Desktop, "Settings" > "Features in development"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论