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

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


Solution 1:[1]

Just found this post: https://github.com/docker/for-mac/issues/5310#issuecomment-779791882

Using this image, I am now able to startup keycloak. https://hub.docker.com/r/wizzn/keycloak

Solution 2:[2]

you can try add this

--platform linux/amd64

from

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

https://github.com/Y2Data

Solution 3:[3]

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
}

Solution 4:[4]

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.

Solution 5:[5]

on M1 running on this image. works for me.

docker run -d -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin wizzn/keycloak:14

Solution 6:[6]

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/amr64/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.

Solution 7:[7]

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

Solution 8:[8]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Etep
Solution 2 li Etzyio
Solution 3
Solution 4 C.Lee
Solution 5
Solution 6 Cesar Flores
Solution 7 eNca
Solution 8 pglezen