Chameleon containers
Sometimes you need to run Docker containers in different circumstances, like on Raspberry Pi's or you have systems that are just wired differently (Alpine) and sometimes even a combination of those (Alpine on a BananaPi) and you do not always have everything laying around to reproduce it. So what do you do?
I ran into this problem because someone was getting a new Apple MacBook with the M1 chip which is ARMv8 or aarch64
and therefore all my previously made Docker images did not work anymore for this person as they did not work for his architecture.
Luckily Alpine and Debian also provide images for the ARMv8 architecture. Yet that meant I had to build two different images and have a multi arch manifest file inside AWS ECR. Which they support and is easy to do, but I did not want to have that plus it made it so difficult to try and reproduce things as I could build cross architecture but not run it yet.
Get yourself QEMU
So the following one line is all you need to make it possible to run as different architectures.
sudo docker run --rm --privileged multiarch/qemu-user-static:register
That will register all the necessary binaries in order to simulate the other architectures. Then for example run the following:
docker run -it --rm multiarch/alpine:aarch64-edge /bin/ash
Then you get an aarch64
image!.
Verify with
uname -a
andarch
Now you can see what it is like to run on those other architectures. The binaries are all of the form qemu-<ARCH>-static
and so there is one for MIPS, SPARC and even PowerPC.