76

I have an m1 mac and I am trying to run a amd64 based docker image on my arm64 based host platform. However, when I try to do so (with docker run) I get the following error:

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

When I try adding the tag --platform linux/amd64 the error message doesn't appear, but I can't seem to go into the relevant shell and docker ps -a shows that the container is immediately exited upon starting. Would anyone know how I can run this exact image on my machine given the circumstances/how to make the --platform tag work?

Frant
  • 5,382
  • 1
  • 16
  • 22
Sabo Boz
  • 1,683
  • 4
  • 13
  • 29

3 Answers3

106

Using --platform is correct. On my M1 Mac I'm able to run both arm64 and amd64 versions of the Ubuntu image from Docker Hub. The machine hardware name provided by uname proves it.

# docker run --rm -ti --platform linux/arm/v7 ubuntu:latest uname -m
armv7l

# docker run --rm -ti --platform linux/amd64 ubuntu:latest uname -m
x86_64

Running amd64 images is enabled by Rosetta2 emulation, as indicated here.

Not all images are available for ARM64 architecture. You can add --platform linux/amd64 to run an Intel image under emulation.

If the container is exiting immediately, that's a problem with the specific container you're using.

Nic
  • 4,319
  • 5
  • 29
  • 36
  • 2
    Thank you so much for that last part - I just want to use a pre-made Docker container for development and don't _care_ that it won't be as fast, just want it to work. Thank you for telling me how to force it. – RyanWilcox Nov 18 '21 at 16:13
  • 1
    How can I get this to work with docker-compose up ? – Oamar Kanji Jan 19 '22 at 04:38
  • 1
    @OamarKanji just add `platform: linux/amd64` in your Compose file – Nic Jan 19 '22 at 05:20
  • 2
    Warning to others: having the `--platform linux/amd64` at the end of the command does not work - it seems to be best placed before declaring the image name! – Boris Yakubchik May 03 '22 at 20:17
  • Is this true? If so why would [this issue be open](https://github.com/docker/roadmap/issues/384)? – KOOTS HOOTS May 20 '23 at 09:04
  • Does not work for me when I have the uname part in. But when I remove the uname and what follows after it works like a charm :) – JRsz May 23 '23 at 09:57
  • also possible to set via `export DOCKER_DEFAULT_PLATFORM="linux/amd64"` if the docker-compose file does not specify this But unfortunately the emaulation give 32 bit cpu as of now – dre-hh Aug 11 '23 at 20:25
4

Just to make sure that --platform linux/amd64 right after 'run'. Otherwise it may does not work. Like this

docker run --platform linux/amd64 image_name

Yuxuan Z
  • 71
  • 2
1

To address the problem of your container immediately exiting after starting, try using the entrypoint flag to overwrite the container's entry point. It would look something like this:

docker run -it --entrypoint=/bin/bash image_name

Credit goes to this other SO answer that helped me solve a similar issue on my own container.

Josh Correia
  • 3,807
  • 3
  • 33
  • 50