how to run arm64 docker images on amd64 host platform
Asked Answered
F

3

6

getting the following error upon attempting to run an image created on my mac m1 to the Docker playground website

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

is there a way to make it possible?

Fong answered 6/8, 2021 at 2:52 Comment(0)
T
4

In my case, I needed to the test the linux/arm64 version of a multiarch image on my Ubuntu(linux/amd64) laptop, just to ensure that it works. When I initially tried to run it, after pulling it using docker pull --platform=linux/arm64 <image-name>, I got the below error:

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

Then I installed qemu-user-static as per one of the instructions on this reddit thread. After that, I was able to run the linux/arm64 image on my x86 laptop. The reddit post has instructions like installing binaries other than qemu-user-static and also mounting the qemu-user-static binary into the container as a volume in the docker run command. I didn't need to do any of that. Just needed to install qemu-user-static(and maybe binfmt-support, which was already installed in my laptop) which I did using sudo apt-get install qemu-user-static.

Tapia answered 29/5, 2023 at 22:36 Comment(2)
Any performance comparison? How many times is slower? For instance how long this takes time dd if=/dev/urandom of=/dev/null bs=1024 count=10000 on amd64 and arm64 images?Messroom
I don't have a personal ARM machine, so will try to test this in CI whenever I have some time. I do have a few personal projects where I build and test separate(or multi-arch) amd64 and arm64 images. I have noticed that the arm64 containers are consistently faster. Sample builds here. In the last 10 builds, average time taken for tests was 63 seconds for amd64 and 51 seconds for arm64. The tests are run in similar sized VMs - 2 CPU/7.5 GB RAM for amd64 and 2 CPU/8 GB RAM for arm64Tapia
I
1

Can you share how you are building your image with us please?

You can build multi arch images from a single host, but you will need to ensure that you pass the correct flags to to Docker when building. In your case, you will need to target linux/amd64 in order to get it to run on the host you are targeting.

The example included in the above article is as such, using docker buildkit:

~/test ❯❯❯ docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t adamparco/demo:latest --push .

Or if you have not enabled buildkit yet (I think it's on be default with docker desktop now), you can use the old way via docker manifests, per this example:

# AMD64
$ docker build -t your-username/multiarch-example:manifest-amd64 --build-arg ARCH=amd64/ .
$ docker push your-username/multiarch-example:manifest-amd64

# ARM32V7
$ docker build -t your-username/multiarch-example:manifest-arm32v7 --build-arg ARCH=arm32v7/ .
$ docker push your-username/multiarch-example:manifest-arm32v7

# ARM64V8
$ docker build -t your-username/multiarch-example:manifest-arm64v8 --build-arg ARCH=arm64v8/ .
$ docker push your-username/multiarch-example:manifest-arm64v8 
Interoceptor answered 6/8, 2021 at 3:17 Comment(0)
P
0

have your dockerfile have this:

FROM --platform=linux/amd64 registry.access.redhat.com/ubi9

Poetize answered 3/7, 2023 at 21:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.