M1 docker preview and keycloak 'image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8)' Issue
Asked Answered
A

14

232

I just downloaded Docker Preview v3.1 https://docs.docker.com/docker-for-mac/apple-m1/ and tried running keycloak.

Anyone else running into this issue?

docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:12.0.4
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Ascites answered 16/3, 2021 at 20:19 Comment(0)
N
335

You can try to add this while building the docker images

--platform linux/amd64

from

https://github.com/google/cadvisor/issues/2763

https://github.com/Y2Data

Natatory answered 16/6, 2021 at 14:16 Comment(8)
Make sure to put this after docker run but before the image name btw.Orthman
If you are building an image on your M1 Mac to be used on Linux then use the --platform linux/amd64 to build a version for Intel chips.Litha
@DanielPorteous why ? It worked even after appending to the end of the entire commandMckee
what if I am building an image on M1 Mac to run on M1 Mac? Like why won't it still work?!Newly
This could work with a warning, depending on the Driver behind your docker-system. I ran it on m1 using Colima, but it uses "emulation" so it's slow and sometimes it hangs. It's better just use an arm64 image from this hub.docker.com/r/sleighzy/keycloak/tagsUnlikelihood
for those using docker-compose, you can add platform: linux/amd64 to the affected images in your docker-compose.ymlShake
This does not work. I tried with an Azure Function project and throws: "WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested"Inapprehensive
@Shake where i have to add platform: linux/amd64 in my docker-compose.yml ?Purview
D
49

Add this snipped to your ~/.zshrc and ~/.bashrc. It allows you not to repeat the flag anytime you perform a docker run command:

# useful only for Mac OS Silicon M1, 
# still working but useless for the other platforms
docker() {
 if [[ `uname -m` == "arm64" ]] && [[ "$1" == "run" || "$1" == "build" ]]; then
    /usr/local/bin/docker "$1" --platform linux/amd64 "${@:2}"
  else
     /usr/local/bin/docker "$@"
  fi
}
Diversion answered 9/12, 2021 at 10:13 Comment(4)
It's probably cleaner to use something like docker() { if ...; then set "$1" --platform linux/amd64 "${@:2}"; fi; command docker "$@"; }Race
For me adding it to the profiles (neither zsh or bash) didn't help. Since in my case docker run executes from another script, helped only adding --platform linux/amd64 to the script itself.Association
@Association what do you get if you prompt which docker from your terminal?Diversion
@AlessandroArgentieri In .zshrc I've put that function docker () {...} and which docker returns me the same. The same function is in .bashrc/.bash_profile. But there which docker gives me just /usr/local/bin/docker. In the previous comment I meant that in my case docker run ... is called from the bash script, so it's a non-login shell and should use .bashrc. But in the end, it seems, it's not.Association
C
35

Similar answer to what @li Etzyio replied, the error is telling you that the platform you are using to build the image locally is a different platform than the one used for the image. This happens for M1 computers (and probably other computers), so, what you have to do is specify the --platform <PLATFORM_SPEC> to the docker build command, and replace the <PLATFORM_SPEC> for the one the error is telling you (in this case linux/arm64/v8).

Also something that had worked for me is to set these environment variables:

export DOCKER_BUILDKIT=0                                                                                                                                                    
export COMPOSE_DOCKER_CLI_BUILD=0
export DOCKER_DEFAULT_PLATFORM=linux/amd64

if you don't want to pass the flag --platform every-time you run the build command.

Corporator answered 23/3, 2022 at 21:55 Comment(5)
Thank you sir. Just bought an M1 Pro and this helped me with Docker Compose, or rather images that I'm consuming, not building. Also confirming that I'm using docker compose v2 and file version v3Bondage
Best answer in this post, thanksBezonian
Thanks. Just this line was enough for this: export DOCKER_DEFAULT_PLATFORM=linux/amd64. And to add it to a script used by different people, I added export DOCKER_DEFAULT_PLATFORM=linux/$(uname -m)Nibelungenlied
How do you set the environment variable? do you just run export DOCKER_DEFAULT_PLATFORM=linux/amd64 in the terminal?Girlhood
@Girlhood yes just type in the terminal or add it in your shell fileCorporator
S
35

On Mac using M1 you need to Enable Rosetta in Docker Desktop (Settings > Features in development). Rosetta is a dynamic binary translator for Mac silicon that allows x86 instructions to be translated into ARM instructions.

enter image description here

You can then specify the default Docker build configuration by setting the following environment variable (note - only do this if you want all Docker containers to use this as the default platform):

export DOCKER_DEFAULT_PLATFORM=linux/amd64

When you next run a Docker build, it will use this as the default platform for the images, and with Rosetta enabled it should now work.

See - https://collabnix.com/warning-the-requested-images-platform-linux-amd64-does-not-match-the-detected-host-platform-linux-arm64-v8/

Stan answered 30/6, 2023 at 5:17 Comment(2)
Thank you! You saved my day! I tried to run keycloak 13.0.1 and got failed with any other approaches: making my own build, using flag --platform, and many others.Ramble
This worked for Mac M2, when running Docker Desktop v4.26.0 as well. But the 'Use Rosetta...' option now lives in the General tab.Shallop
O
22

If you run Docker Workstation on an M1 mac, you can leverage the Docker Workstation multi-CPU architecture support, which includes the buildx command. It allows you to create images for different CPUs.

To build a Linux/AMD/Intel image on your M1 mac workstation, run the following.

docker buildx build --platform=linux/amd64 -t myorg/mytag:1.0.0 .

Placing docker buildx in front starts the command with BuildKit. See the links above for details.

Orphanage answered 6/5, 2022 at 16:53 Comment(3)
Thanks! This helped me deploy images I build on my M1 mac to labs.play-with-docker.comPrevision
Great answer; I was building the image on an M1 Mac and needing it to run in Jenkins (Linux). After doing it this way, Jenkins had no problem using the image. Thanks!Dynamotor
This helped me get the docker getting-started app on play-wtih-docker as well. I ran into other issues, the build was taking very long. Eventually debugged to get npm to not audit RUN npm install --production --no-audit in the Dockerfile. I also had to add the flag --network="host" at the end of the command. docker buildx build --platform=linux/amd64 -t getting-started . --network="host"Foxworth
F
8

The following will do the trick when building images on M1 machines:

docker build -t <image-name> --platform linux/x86_64
Falgoust answered 10/6, 2022 at 9:21 Comment(0)
N
5

Setting the "Use Rosetta for x86/amd64 emulation on Apple Silicon" config in the docker desktop helped me resolve this issue - Docker Setting

Nonfulfillment answered 12/7, 2023 at 5:18 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mechanics
B
3

I also had this problem when I upgraded to a new version

I fix it by delete all images was builded by old version "docker system prune --all" and re build image

Biaxial answered 15/7, 2022 at 12:47 Comment(1)
this is the easiest and best solution if you end up here after installing an M1 mac from a time machine backup that had all amd64 images!!!Ciscaucasia
H
2

The root cause the same as in the following threads:

Forcing docker to use linux/amd64 platform by default on macOS

Docker on Mac M1 gives: "The requested image's platform (linux/amd64) does not match the detected host platform"

There is a 'fix' for docker-compose.yml approach as well.

Holotype answered 27/2, 2023 at 18:27 Comment(0)
B
2

same issue ate my lot of time, I finally understand what was happening in my case.

short answer --platform linux/amd64 will work if you are building the fresh image from public base image(most of the times)

A very normal use-case is pulling the base image from Private Repositories I did following steps.

  1. build base image on M1
  2. push the base image manually to ECR (some private repository)
  3. Use this base image to build deployable image (this was happening in pipeline linux ENV)
  4. Started getting WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
  5. Wasted Lot of time debugging the deployable image.

The main issue here was Base image was build on M1 without --platform linux/amd64.

Hope it saves someones time :)

Breakthrough answered 11/1 at 19:20 Comment(0)
V
0

I had this issue because in my Dockerfile i used FROM java:8 which doesn't support arm64.

I fix it by running the following command:

docker pull openjdk

then changed my Dockerfile to

FROM openjdk:latest
Vassaux answered 21/4, 2022 at 14:31 Comment(0)
A
-1

For me, the error happened because I build the docker image on an M1 chip Macbook, and tried to run the image on a Linux machine.

This worked for me:

Build the docker image using the same machine that needs to run it, and it worked.

Attack answered 16/12, 2021 at 3:54 Comment(2)
This defeats the primary reason for using docker containers.Barocchio
@PeterMoses well, kind of, but in my case, I have to run the same docker container on multiple servers / worker-nodes, so the answer solves the exact problem for me.Attack
B
-2

This solves the porblem in Mac too

docker pull openjdk then changed my Dockerfile to

FROM openjdk:latest

Bid answered 19/8, 2022 at 22:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.