Arm emulation on apple silicon fails with a QEMU error

arm (note, not arm64) emulation seems to tickle a bug in QEMU, this is with the latest version of docker desktop:

cat > Dockerfile <<eof
FROM balenalib/rpi-raspbian:bullseye-20210925

USER root

RUN apt-get update -y && apt-get upgrade -y
eof
docker build  .

leads to the following error:

[2/2] RUN apt-get update -y && apt-get upgrade -y:
#6 1.018 Get:1 Index of /debian bullseye InRelease [23.5 kB]
#6 1.018 qemu: uncaught target signal 4 (Illegal instruction) - core dumped
#6 1.075 Reading package lists…
#6 1.193 E: Method http has died unexpectedly!
#6 1.194 E: Sub-process http received signal 4.

It seems you are not alone with this:

They say what you suspected that it is a qemu bug.

There is also a bug report in balenalib github repository:

The error message is different but I suspect the reason is the same. If you try to run the “buster” version you will get the other error message referring to “apt-key”.

At the end of the issue you can find a link to the balena forum:

I don’t know balena so I don’t really understand what they say there but it might help you.