Running arm64 docker container on x86

Make sure to install the packages mentioned in Multi-platform builds, which then will allows docker to leverage qemu, which then emulates the target cpu architecture.

binfmt

Use the tonistiigi/binfmt image to install QEMU and register the executable types on the host with a single command:

$ docker run --privileged --rm tonistiigi/binfmt --install all

This installs the QEMU binaries and registers them with binfmt_misc, enabling QEMU to execute non-native file formats for emulation.

Once QEMU is installed and the executable types are registered on the host OS, they work transparently inside containers. You can verify your registration by checking if F is among the flags in /proc/sys/fs/binfmt_misc/qemu-*.

docker

Once the prerequisites are installed you can build and run images for other cpu architectures like this:

docker build --platform linux/arm64 -t test .
docker run --platform linux/arm64 test

To run ubuntu on aarch64:

docker run -itd -v /opt/shared:/opt/shared --name arm64v8 arm64v8/ubuntu
docker exec -it arm64v8 /bin/bash

Leave a Reply

Your email address will not be published. Required fields are marked *