How to run armhf docker on x86

Hi,
i found a few setups on the web on how to get a armhf docker running on x86. I followed for example this:
https://matchboxdorry.gitbooks.io/matchboxblog/content/blogs/build_and_run_arm_images.html
and this

in short i created a debian12 VM an ran:

    sudo apt-get update && sudo apt-get install -y --no-install-recommends qemu-user-static binfmt-support
    sudo update-binfmts --enable qemu-arm
    sudo update-binfmts --display qemu-arm
    sudo apt-get install ca-certificates curl
    sudo install -m 0755 -d /etc/apt/keyrings
    sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
    sudo chmod a+r /etc/apt/keyrings/docker.asc
    echo   "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" |   sudo tee etc/apt/sources.list.d/docker.list > /dev/null
    sudo apt-get update
    sudo apt-get install docker
    sudo groupadd docker
    sudo usermod -aG docker $USER
    docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -c yes

which succeded, i then try to run:

docker run -it --rm -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static arm32v7/debian /bin/sh

and

docker run -it --restart always     -v /usr/bin/qemu-arm-static:/usr/bin/qemu-arm-static     arm32v7/debian /bin/sh

which both wont run with the note that:

Unable to find image 'arm32v7/debian:latest' locally
latest: Pulling from arm32v7/debian
docker: no matching manifest for linux/amd64 in the manifest list entries.
See 'docker run --help'.

Iā€™d expect it not to use linux/amd64 but the armv7 stuff but it doesnā€™t.

ls /proc/sys/fs/binfmt_misc
python3.11       qemu-alpha  qemu-hexagon  qemu-microblaze    qemu-mips64    qemu-mipsn32    qemu-ppc      qemu-riscv32  qemu-sh4    qemu-sparc32plus  qemu-xtensaeb
qemu-aarch64     qemu-arm    qemu-hppa     qemu-microblazeel  qemu-mips64el  qemu-mipsn32el  qemu-ppc64    qemu-riscv64  qemu-sh4eb  qemu-sparc64      register
qemu-aarch64_be  qemu-armeb  qemu-m68k     qemu-mips          qemu-mipsel    qemu-or1k       qemu-ppc64le  qemu-s390x    qemu-sparc  qemu-xtensa       status

ls /usr/bin/qemu-arm-static 
/usr/bin/qemu-arm-static

I obviously am doing something wrong but can currently not see what. Can someone spot it?
Thanks

Use Dockerā€™s --platform option. You donā€™t need to mount any emulator into the container.

2 Likes

That is absolutely rigth, i just missed the --platform :slight_smile: thanks. Now when i run:

 docker run --platform=linux/arm64/v8 --rm debian:latest uname -m

its output is:

aarch64

But it seems to be VERY slow when trying to get a shell. Is that to be expected? For example when i run above command it returns almost immediately but when i try to get a bash in the container like

docker run --platform=linux/armhf --rm -t debian:latest /bin/bash
root@211244bce976:/# ls

it seems to be stuck. Allthough when ran directly it just returns fineā€¦

docker run --platform=linux/armhf --rm debian:latest ls
bin
boot
dev
etc
home
lib
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var

Emulation is never perfect and the performance will be worse than when you donā€™t emulate. Some applications cannot even run emulated.

When you run the ls command in the container, that indeed runs in a shell. When you run it directly through the docker run command, ls runs the /usr/bin/ls binary, directly. So it seems that the emulation of the armhf-based bash shell is slow on x86_64 systems.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.