2

My server and docker info. are as follows:

Linux xxx 3.10.0-1160.66.1.el7.x86_64 #1 xxx x86_64 x86_64 x86_64 GNU/Linux

Docker version 20.10.17

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Server Version: 20.10.17
 Kernel Version: 3.10.0-1160.66.1.el7.x86_64
 Operating System: CentOS Linux 7 (Core)
 OSType: linux
 Architecture: x86_64

I want to build a docker container by QEMU. I followed the instructions from the official QEMU github. But it gave errors.

$ uname -m
x86_64

$ docker run --rm -t arm64v8/ubuntu uname -m
WARNING: The requested image's platform (linux/arm64/v8) does not match the detected host platform (linux/amd64) and no specific platform was requested
exec /usr/bin/uname: exec format error

Then I found a similar docker problem on stackoverflow. I tried both docker build and docker buildx, and it still doesn't work.

$ docker build --platform linux/arm64/v8 .
unable to prepare context: unable to evaluate symlinks in Dockerfile path: lstat /work/home/chenning/Dockerfile: no such file or directory


$ docker buildx build --push --platform linux/amd64,linux/arm64 -t <tag> .
-bash: tag: No such file or directory

I also tried the following instruction, but it still reported errors.

$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
sh: write error: Invalid argument
Setting /usr/bin/qemu-alpha-static as binfmt interpreter for alpha
Setting /usr/bin/qemu-arm-static as binfmt interpreter for arm
sh: write error: Invalid argument
Setting /usr/bin/qemu-armeb-static as binfmt interpreter for armeb
sh: write error: Invalid argument
Setting /usr/bin/qemu-sparc-static as binfmt interpreter for sparc
sh: write error: Invalid argument
...

I followed the guide from this link

it works when I try

docker run --rm --privileged multiarch/qemu-user-static:register

I have qemu interpreters (including qemu-aarch64) in /proc/sys/fs/binfmt_misc

My qemu-aarch64 is like this

enabled
interpreter /usr/bin/qemu-aarch64-static
flags:
offset 0
magic 7f454c460201010000000000000000000200b700
mask ffffffffffffff00fffffffffffffffffeffffff

but I don't have the permission to change flags, I also don't have interpreter /usr/bin/qemu-aarch64-static.

Can I get some help, pls?

kinder chen
  • 1,371
  • 5
  • 15
  • 25
  • Show the Dockerfile you are building and the directory listing showing it exists. What is your host, what distribution and version of Linux, and what qemu components and versions have you installed? – BMitch Sep 22 '22 at 13:06
  • hi, I just added the info. you asked. – kinder chen Sep 22 '22 at 14:58
  • If I were to guess, this is a combination of an extremely old kernel version and possibly SELinux. The lack of flags means binfmt misc was installed without the required options to work with containers, and that tends to mean you need a newer install of a package, probably from something newer than CentOS 7. – BMitch Sep 22 '22 at 15:28

3 Answers3

1

I got the same error, but executing this command fixed the issue:

$ docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

So I can even spawn a shell:

$ docker run -it arm64v8/ubuntu /bin/bash
root@0b6162g03ka5:/# uname -m
aarch64

If it doesn't work take a look at this issue, otherwise you should create a new issue on github

k1r1t0
  • 465
  • 2
  • 11
  • I also tried it, but it gave a bunch of errors like this `sh: write error: Invalid argument Setting /usr/bin/qemu-alpha-static as binfmt interpreter for alpha Setting /usr/bin/qemu-arm-static as binfmt interpreter for arm ` – kinder chen Sep 22 '22 at 12:32
  • What's the output of `ls /proc/sys/fs/binfmt_misc/`? Try this link: https://github.com/multiarch/qemu-user-static/issues/38 – k1r1t0 Sep 22 '22 at 12:38
  • kshcomp register status – kinder chen Sep 22 '22 at 12:38
  • Try to run `run.sh` script before doing anything to docker, that should set up binfmt for procfs – k1r1t0 Sep 22 '22 at 12:41
  • I tried `docker run --rm --privileged multiarch/qemu-user-static:register`, then `ls /proc/sys/fs/binfmt_misc` gave `kshcomp qemu-aarch64 qemu-aarch64_be ... register status`, what shall do next? – kinder chen Sep 22 '22 at 13:41
  • I find I don't have the interpreter `/usr/bin/qemu-aarch64-static` – kinder chen Sep 22 '22 at 14:03
  • Is `docker run --rm -t arm64v8/ubuntu uname -m` this command still failing? After running the first command you should have all needed interpreters – k1r1t0 Sep 22 '22 at 14:20
  • Oh, sorry, after running this command `docker run --rm --privileged multiarch/qemu-user-static --reset -p yes` – k1r1t0 Sep 22 '22 at 14:24
  • it still shows "does not match" error, I also don't have the interpreter `/usr/bin/qemu-aarch64-static`, it it possible bcz of that I don't have root permission? – kinder chen Sep 22 '22 at 14:28
  • `cat /proc/sys/fs/binfmt_misc/qemu-aarch64`? I think if you don't have root permission you'll get `Permission Denied`. Also, don't try to find the interpreter in you actual `/usr/bin` directory, all these done as a pseudo files for binfmt I guess and please check the link I provided earlier. As they're said if the problem still exists it's possible that you found a bug and should create a new issue on github – k1r1t0 Sep 22 '22 at 14:35
  • if I do `docker run --rm --privileged multiarch/qemu-user-static --reset -p yes`, I have nothing at `cat /proc/sys/fs/binfmt_misc`, I also updated the question. – kinder chen Sep 22 '22 at 14:59
  • What's the output of `# echo ":qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64-static:F" > /proc/sys/fs/binfmt_misc/register` just after your last question's update – k1r1t0 Sep 22 '22 at 15:05
  • This will not solve OP's problem: it will work for Ubuntu, but not Centos. That's because Centos does not supply static version of the QEMU interpreters. See [this post](https://stackoverflow.com/questions/72455086/i-can-set-up-an-arm64-docker-image-but-cant-run-anything) for the solution. – Spokes Mar 20 '23 at 13:11
0

--ignorearch this will save you from misery.

Turgut
  • 31
  • 1
  • 1
  • 6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 24 '23 at 21:25
0

For me installing qemu was sufficient

sudo apt install qemu-user qemu-user-static gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu binutils-aarch64-linux-gnu-dbg build-essential
Aramakus
  • 1,910
  • 2
  • 11
  • 22