Etep
Etep

Reputation: 3601

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

Upvotes: 264

Views: 411926

Answers (17)

Wolfack
Wolfack

Reputation: 2769

Using Docker Compose

Here's an example of a Docker Compose file that specifies the platform as linux/amd64:

services:
  web:
    platform: linux/amd64
    image: nginx:latest
    ports:
      - "8080:80"

In this example, we have a single service called web that uses the nginx:latest image, which is built for the linux/amd64 platform. We've also specified that the service should be accessible on port 8080 on the host machine, which is mapped to port 80 inside the container.

Upvotes: -2

Jayantha
Jayantha

Reputation: 2349

This resolves my issue

export DOCKER_DEFAULT_PLATFORM=linux/amd64

then

docker-compose up -d

from -> https://github.com/google/cadvisor/issues/2763

Upvotes: 8

Obinna Nnenanya
Obinna Nnenanya

Reputation: 1818

There are already great answers here. In my case with postgres, I had to search for the platform-specific image HERE. Then run with DOCKER_DEFAULT_PLATFORM=linux/amd64.

In my Dockerfile:

FROM amd64/postgres:14.3

Then I run my docker-compose with

DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose up

For details:

My Dockerfile

FROM amd64/postgres:14.3
LABEL author="Obinna"
LABEL description="Postgres Image"
LABEL version="1.0"

My docker-compose.yml

services:
  postgres:
    env_file:
      - .env
    build:
      context: .
    image: "postgres-inventory-manager"
    container_name: ${PG_CONTAINER_NAME}
    volumes:
       - postgres:/var/lib/postgresql/data
    ports:
       - "5444:5432"
    restart: unless-stopped
volumes:
  postgres:

Upvotes: 0

chandrakant kaski
chandrakant kaski

Reputation: 417

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 :)

Upvotes: 6

Shivanand Swamy
Shivanand Swamy

Reputation: 51

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

Upvotes: 5

Chris Halcrow
Chris Halcrow

Reputation: 31940

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/

Upvotes: 44

Maksym Kosenko
Maksym Kosenko

Reputation: 595

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.

Upvotes: 2

Cesar Flores
Cesar Flores

Reputation: 1151

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.

Upvotes: 45

li Etzyio
li Etzyio

Reputation: 3807

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

Upvotes: 379

Vishwanatha N
Vishwanatha N

Reputation: 9

This solves the porblem in Mac too

docker pull openjdk then changed my Dockerfile to

FROM openjdk:latest

Upvotes: -3

longhust
longhust

Reputation: 31

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

Upvotes: 3

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39790

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

docker build -t <image-name> --platform linux/x86_64

Upvotes: 10

pglezen
pglezen

Reputation: 1021

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.

Upvotes: 25

tcon163
tcon163

Reputation: 11

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

Upvotes: 0

C.Lee
C.Lee

Reputation: 11249

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.

Upvotes: -1

Alessandro Argentieri
Alessandro Argentieri

Reputation: 3215

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
}

Upvotes: 51

Related Questions