docker build --platform=linux/amd64 fails: ERROR: failed to solve: no match for platform in manifest
Asked Answered
A

4

13

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:

  1. 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
  1. I know that rosetta qemu emulation works, because I can run
$ docker run --rm -ti --platform linux/amd64 alpine:latest uname -m
x86_64
  1. 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?

Albright answered 29/5, 2023 at 8:51 Comment(2)
Are you using Docker Desktop? Which version?Grange
I am using docker desktop 4.19.0 (most recent as of writing)Dalrymple
G
19

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"

Grange answered 29/5, 2023 at 15:23 Comment(3)
Disabling the setting mentioned, worked and solved my problem. Thanks @Alez.Dalrymple
This still seems to be an issue in 4.20.1.Isaacson
Seems to be properly fixed in BuildKit v0.12.0. When exporting an image to Containerd image store, unpack logic now works for multi-platform images by unpacking only the native platform by default #3982 #3983 Not yet landed in moby: github.com/moby/moby/pull/45966Jedjedd
M
5

Following up from Kraken's post. I was getting the "no match for platform in manifest" error when trying to build with an aws lambda image on a Macbook Pro with an M3 chip because of a typo in my --platform=XXXX flag.

Successful build command with --platform flag: docker build -t my-custom-lambda . --platform=linux/amd64 --no-cache

Mayhem answered 1/4 at 10:51 Comment(0)
S
3

Another possible cause for this error could be an invalid platform string. Sending an invalid platform string will prevent docker from parsing the correct tag, i.e. --platform=linux/amd will fail, whereas --platform=linux/amd64 succeeds.

Siriasis answered 13/12, 2023 at 15:13 Comment(0)
I
0

Following this post, I found this to work

"docker build -t dennis . --platform=linux/arm64 --no-cache"
Irma answered 14/5 at 8:29 Comment(1)
Welcome to SO! It seems your answer does not add anything over the existing ones? Once you have gained sufficient reputation, you will be able to upvote existing answers and/or add comments to them. Also see stackoverflow.com/help/how-to-answerRisible

© 2022 - 2024 — McMap. All rights reserved.