qemu-user-static icon indicating copy to clipboard operation
qemu-user-static copied to clipboard

Can't run quemu-static on arm64v8/ubuntu:20.04

Open Corallo opened this issue 2 years ago • 4 comments

Description: I am trying to reproduce the first example of this simple guide: https://www.balena.io/blog/building-arm-containers-on-any-x86-machine-even-dockerhub/

on an arm64v8/ubuntu:20.04 image.

But I get an incompatible ELF error when building

Step tu reproduce Docker file:

FROM arm64v8/ubuntu:20.04 as build-base-arm 
COPY --from=multiarch/qemu-user-static:x86_64-arm-6.1.0-8 /usr/bin/qemu-arm-static /usr/bin/qemu-arm-static 
RUN [ "/usr/bin/qemu-arm-static", "/bin/echo", "Hello from ARM container" ]

On shell: docker build .

Describe the results you received: ---> [Warning] The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested ---> Running in 8fb3cc786c60 qemu-arm-static: /bin/echo: Invalid ELF image for this architecture

Describe the results you expected: Hello, world!

Environment: I am on a fresh Ubuntu:20:04

Output of docker version, podman version or singularity version

[255] angelod@lap5cg1375wnh> docker version                                                                                                                                  ~/Desktop/arm64-docker/test
Client: Docker Engine - Community
 Version:           20.10.10
 API version:       1.41
 Go version:        go1.16.9
 Git commit:        b485636
 Built:             Mon Oct 25 07:42:59 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.10
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.9
  Git commit:       e2f740d
  Built:            Mon Oct 25 07:41:08 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0


Additional information optionally: I don't have podman/singularity

Corallo avatar Dec 02 '21 13:12 Corallo

You need to run docker run -it --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes first. See https://martin-grigorov.medium.com/building-linux-packages-for-different-cpu-architectures-with-docker-and-qemu-d29e4ebc9fa5

martin-g avatar Dec 02 '21 13:12 martin-g

You need to run docker run -it --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes first. See https://martin-grigorov.medium.com/building-linux-packages-for-different-cpu-architectures-with-docker-and-qemu-d29e4ebc9fa5

I tried to follow the instructions in your article, but it seems there's still something missinig: after docker run -it --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes, I get the expected output, several Setting /usr/bin/qemu-...-static as binfmt interpreter for .... However, when I run: docker run -it --rm arm64v8/centos:8 uname -m I get

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

which is unexpected

Corallo avatar Dec 02 '21 15:12 Corallo

To avoid the warning you need to pass --platform linux/arm64:

docker run --platform linux/arm64 -it --rm arm64v8/centos:8 uname -m

martin-g avatar Dec 03 '21 08:12 martin-g

I see, the warning was just saying that the docker image and the host machine have different architecture, the actuall error disappeared after running your command: docker run -it --rm --privileged multiarch/qemu-user-static --credential yes --persistent yes Thanks a lot for the help!

Corallo avatar Dec 03 '21 13:12 Corallo