2

I have Raspberry PI 4 with 8 GB memory. And I have x86 container. It is working on x86/amd64 servers correctly. I would like to port it to raspberry. It has ubuntu 22 released from Raspberry team. I read there is qemu-user-static, kvm and looks like x86 docker's container on arm64 are supported but I can't get any result. I can see my Raspberry supports kvm.

    root@ubuntu:/home/ubuntu# virt-host-validate
  QEMU: Checking if device /dev/kvm exists                                   : PASS
  QEMU: Checking if device /dev/kvm is accessible                            : PASS
  QEMU: Checking if device /dev/vhost-net exists                             : PASS
  QEMU: Checking if device /dev/net/tun exists                               : PASS
  QEMU: Checking for cgroup 'cpu' controller support                         : PASS
  QEMU: Checking for cgroup 'cpuacct' controller support                     : PASS
  QEMU: Checking for cgroup 'cpuset' controller support                      : PASS
  QEMU: Checking for cgroup 'memory' controller support                      : PASS
  QEMU: Checking for cgroup 'devices' controller support                     : PASS
  QEMU: Checking for cgroup 'blkio' controller support                       : PASS
  QEMU: Checking for device assignment IOMMU support                         : WARN (Unknown if this platform has IOMMU support)
  QEMU: Checking for secure guest support                                    : WARN (Unknown if this platform has Secure Guest support)
   LXC: Checking for Linux >= 2.6.26                                         : PASS
   LXC: Checking for namespace ipc                                           : PASS
   LXC: Checking for namespace mnt                                           : PASS
   LXC: Checking for namespace pid                                           : PASS
   LXC: Checking for namespace uts                                           : PASS
   LXC: Checking for namespace net                                           : PASS
   LXC: Checking for namespace user                                          : PASS
   LXC: Checking for cgroup 'cpu' controller support                         : PASS
   LXC: Checking for cgroup 'cpuacct' controller support                     : PASS
   LXC: Checking for cgroup 'cpuset' controller support                      : PASS
   LXC: Checking for cgroup 'memory' controller support                      : PASS
   LXC: Checking for cgroup 'devices' controller support                     : PASS
   LXC: Checking for cgroup 'freezer' controller support                     : FAIL (Enable 'freezer' in kernel Kconfig file or mount/enable cgroup controller in your system)
   LXC: Checking for cgroup 'blkio' controller support                       : PASS
   LXC: Checking if device /sys/fs/fuse/connections exists                   : PASS

Looks like I am doing something wrong but this technology is obviously not easy and there is no way to understand it quickly. Internet has not a of lot info but it is about other tasks. May be someone got this way and could push me to the right direction.

So usually I starts my container by this way:

docker run -d --privileged --restart unless-stopped --hostname mycontainer --net=host --name=mycontainer -it mycontainer:v1 /bin/bash /entrypoint.sh

and with installed qemu-user-static, qemu-system and all other qemu libraries it started but doesn't work.

I read the following info: Need to run it inside qemu container by following way:

docker run --rm -it --device=/dev/kvm:/dev/kvm --device=/dev/net/tun:/dev/net/tun     --cap-add NET_ADMIN -v /home/ubuntu/mycontainer_v1.xz:/image jkz0/qemu:latest

It gives the following error:

root@ubuntu:/home/ubuntu# docker run --rm -it     --device=/dev/kvm:/dev/kvm --device=/dev/net/tun:/dev/net/tun     --cap-add NET_ADMIN -v /home/ubuntu/readyImages/adapter2_2.xz:/image     jkz0/qemu:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
udhcpd: started, v1.30.1
udhcpd: max_leases=235 is too big, setting to 1
udhcpd: can't open '/var/lib/misc/udhcpd.leases': No such file or directory
kvm version too old
qemu-system-x86_64: failed to initialize KVM: Function not implemented

Did someone touch this issue before? I need fresh ideas. Best regards, Dmitry

4
  • 2
    Could you build your container image for arm64 (as well as x86-64) instead of trying to run an x86-64 image on arm64? Commented Nov 23, 2023 at 12:58
  • Thanks you for your answer. It is not possible. It is ported container from real server. Not possible to rebuild it. Commented Nov 23, 2023 at 13:18
  • Docker containers are usually built from Dockerfiles, and you should be able to change the architecture by building with a different FROM line. If you do not have a Dockerfile to build your container, then I am not sure there is an easy answer except to redo everything you did in an arm64 container. Commented Nov 23, 2023 at 20:37
  • This container was extracted from real X86 server. Server was specially prepared next I extracted image of server and put it to container. So there was not Dockerfile. It is not possible to rebuild it because it was created by another way. So.. It is working inside docker under X86_64 architecture very well. But it is not working under arm64 over qemu. It is the issue. Commented Nov 24, 2023 at 19:36

2 Answers 2

0

So, I don't know about docker – but docker is "just" a runtime for OCI containers (and frankly, I find it's sometimes too much, it does a lot that I don't need). The same "docker containers" can be run using podman (which even has a relatively compatible CLI), and podman supports running containers in a VM right out of the box; all you need is an x86_64 coreOS VM image; you will have to fiddle with the VM configuration a bit manually, podman does not (yet?) have command line options for that.

Small preparation necessary: I don't know which machines your qemu supports, so run qemu-system-x86_64 -cpu help | grep -v 'alias ', and pick one that firs your needs; I'll just use Nehalem-v2, you replace that with something sensible where it occurs below!

podman machine init \
      --image-path YOUR_DOWNLOADED_FEDORA_COREOS-qemu.x86_64.qcow2.xz_IMAGE \
      x86_64_machine

Edit $XDG_CONFIG_HOME/containers/podman/machine/qemu/x86_64_machine.json; find the "CmdLine" property, a list; in that list, find "-cpu"; the next line probably says "host", which is not what you want here; replace that with your desired qemu CPU model (Nehalem-v2 in my case). Make sure "-accel" is "kvm".

So now that this is set up correctly, configure podman to always use that by default. podman system connection default x86_64_machine does that.

Start the VM, podman machine start x86_64_machine; this might take a while on an Rpi!

After it was started successful, you can run your favorite docker containers; podman run --rm -it fedora:39 uname -a should pull a Fedora 39 container (x86_64!), and run uname -a in it; after that finishes, the container will be removed (--rm) again.

6
  • Thank you very much Marcus for such detailed description. But it doesn't work. I have very big list of available CPU but with almost all I see the following: qemu-system-aarch64: unable to find CPU model 'phenom-v1' Nehalem doesn't work of course. Working only "max" and "host". But with these settings container started but software doesn't work inside. Commented Nov 27, 2023 at 17:24
  • qemu-system-aarch64 can't emulate x86 :) you need to replace that with qemu-system-x86_64 Commented Nov 27, 2023 at 17:30
  • Marcus. Looks like you are typing something right but may be I am so stupid I can't implement this. Of course I understand need to use qemu-system-x86_64 but how to push docker or podman to do this. Actually I see my x86 container is started. But inside container I tried to start needed bin file then I got exec format error. Commented Nov 28, 2023 at 12:48
  • your ...machine.json file specifies the wronq qemu. Check the first line of CmdLine. Commented Nov 28, 2023 at 13:00
  • Thank you Marcus. But I got next step of this puzzle. I got the following error: ubuntu@ubuntu:~$ podman machine start x86_64_machine Starting machine "x86_64_machine" Waiting for VM ... Error: qemu exited unexpectedly with exit code 1, stderr: qemu-system-x86_64: unsupported machine type Use -machine help to list supported machines When I type: qemu-system-x86_64 -machine help Supported machines are: microvm microvm (i386) pc-i440fx-zesty Ubuntu 17.04 PC (i440FX + PIIX, 1996) and so one. A lot of machine. Where need to configure type of machine? Commented Nov 28, 2023 at 18:47
-1

You just can't it's not possible as the architecture differs.

Two ways to do achieve this are :

6
  • It's possible; docker-for-windows and docker-for-macos is a good demonstration of Linux-container-in-VM working necessarily with the standard infrastructure. Commented Nov 23, 2023 at 16:01
  • You seems to confuse the runtime environment (docker-for-windows and docker-for-macos ) docker is NOT a VM there is no emulation layer wich permit to translate the container image with binaries from an architecture to another... Commented Nov 23, 2023 at 16:08
  • no, I'm not. Docker-for-Windows starts a Linux VM and runs the containers inside. IBM advertises methods to run x86_64 containers on their aarch64 cloud … you know, see my answer, where I actually explain how to do what you say is impossible :) Commented Nov 23, 2023 at 16:09
  • Yes that's what I called "runtime environment" as said in my answer if you want to run x86/amd84 docker images built for this arch on arm arch you need to have a virtualization layer as you explain in your docker-for-windows example. Commented Nov 23, 2023 at 16:12
  • @MarcusMüller please post details about IBM method on how to run x86_64 on aarch64. Commented Nov 23, 2023 at 16:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .