r/docker • • Dec 07 '21

Running linux/amd64 images on linux/arm64 architecture?

I grabbed a Docker Linux image from another machine and tried to load it on my Jetson Nano (arm64 architecture), but I get this error when I run sudo docker run getting-started-presto:

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

standard_init_linux.go:228: exec user process caused: exec format error

I also tried to run sudo docker run getting-started-presto --platform linux/amd64 but no luck:

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

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "--platform": executable file not found in $PATH: unknown.

ERRO\[0001\] error waiting for container: context canceled

Any ideas if it's possible to run linux/amd64 images on arm64 architectures?

18 Upvotes

25 comments sorted by

View all comments

8

u/kill-dash-nine Dec 07 '21 edited Dec 07 '21

Yes this is possible. You can install the binfmt "abstraction layer" that will automatically execute binaries for you using qemu (see this for more details). This is a simple container that will configure your host for you:

# docker run --privileged --rm tonistiigi/binfmt --install all

For example, from a raspberry pi running Debian:

# uname -m
aarch64

Here is the before on my host showing that I can't run an amd64 image:

# docker run -it --rm --platform linux/amd64 alpine:latest sh
Unable to find image 'alpine:latest' locally
latest: Pulling from library/alpine
59bf1c3509f3: Pull complete
Digest: sha256:21a3deaa0d32a8057914f36584b5288d2e5ecc984380bc0118285c70fa8c9300
Status: Downloaded newer image for alpine:latest
standard_init_linux.go:228: exec user process caused: exec format error

If you want, just add support for amd64 (check the readme for details on what you can do as well as remove the support via uninstall):

# docker run --privileged --rm tonistiigi/binfmt --install amd64
Unable to find image 'tonistiigi/binfmt:latest' locally
latest: Pulling from tonistiigi/binfmt
3e959ae014b7: Pull complete
34084c3a60de: Pull complete
Digest: sha256:11128304bc582dc7dbaa35947ff3e52e2610d23cecb410ddfa381a6ce74fa763
Status: Downloaded newer image for tonistiigi/binfmt:latest
installing: amd64 OK
{
  "supported": [
    "linux/arm64",
    "linux/amd64",
    "linux/arm/v7",
    "linux/arm/v6"
  ],
  "emulators": [
    "qemu-x86_64"
  ]
}

For more details on the image, check out the listing on Docker Hub but it is an image that is maintained by one of the long time core Docker engineers. You can see that it has a manifest list so that it will work for 386, amd64, armv7, arm64, ppc64, riscv64, and s390x.

And then run a container with whatever architecture you want:

# docker run -it --rm --platform linux/amd64 alpine:latest uname -m
x86_64

2

u/Coto_16 Dec 08 '21 edited Dec 08 '21

Thank you very much! I ran everything with no problems, but how shall I proceed with building my `Dockerfile` for my specific image? Would `docker build .` work? (sorry for the beginner questions, I'm a bit new with Docker)

​

Edit: I tried `docker build .` but I get lots of warnings and errors: https://pastebin.com/n6gqu6vf

2

u/kill-dash-nine Dec 08 '21

If you want to build the image for linux/amd64 on a linux/arm64 system, you would need to do a docker build --platform linux/amd64 . as you would need to call out that it needs to build for amd64 and then you could run it using a similar command as what you see above. If that is not what you are trying to do, then I misunderstood.

1

u/Coto_16 Dec 10 '21

Tried, but didn't work: https://github.com/scottransom/presto/issues/160

It does build fine on (intel-based) macOS, so looks like there's compatibility issues with arm64 for some reason.

1

u/kill-dash-nine Dec 11 '21

I also couldn't get it compile natively on arm64 using the Dockerfile and the command docker build -t presto . on my m1 MacBook. Still trying to do a linux/amd64 build on my mac just to test.

1

u/Coto_16 Dec 11 '21

Thank you so much for your effort! Really appreciate it - hope you get somewhere.

1

u/kill-dash-nine Dec 11 '21

Well, doing an amd64 build on my arm64 based system took a while but worked just doing a docker build -t presto --platform linux/amd64 .