If you are running a multi-architecture setup in test and production, whereas doing primary application development on your Intel laptop or cloud provider instances, then having a mechanism to functionally verify the application for multiple-architectures might come in handy.

In this blog, we’ll explore some of the available approaches to build and test Power(ppc64le) Docker images on your Intel (x86_64) system running Linux. You’ll most likely want to use this as part of your development workflow to verify and test your application to ensure its multi-arch capable before deploying it in test/production.

We’ll see how to leverage Qemu and Linux binfmt_misc capability to build and test Docker images for Power (ppc64le) architecture on Intel.

Qemu is an emulator and virtualizer and has two operating modes:

Full system emulation: In this mode, Qemu emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch a full-fledged Operating System built for one CPU architecture (eg. Power) on another CPU architecture (eg. Intel).

In this mode, Qemu emulates a full system (for example a PC), including one or several processors and various peripherals. It can be used to launch a full-fledged Operating System built for one CPU architecture (eg. Power) on another CPU architecture (eg. Intel). User mode emulation: In this mode, Qemu can launch binaries compiled for one CPU architecture on another CPU architecture.

This article describes how to leverage Qemu user mode emulation.

Setup

The Linux system needs to be setup to use Qemu user mode emulation. For this, we need to register the appropriate Qemu binary as the interpreter/handler for any Power binaries.

Download Qemu static binary

# wget https://github.com/multiarch/qemu-user-static/releases/download/v3.1.0-2/qemu-ppc64le-static -O /usr/bin/qemu-ppc64le-static # chmod +x /usr/bin/qemu-ppc64le-static

Register with ‘F’ flag

# echo ':qemu-ppc64le:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00:/usr/bin/qemu-ppc64le-static:F' > /proc/sys/fs/binfmt_misc/register

After running the above command, you should see the following output on the host.

# cat /proc/sys/fs/binfmt_misc/ppc64le enabled interpreter /usr/bin/qemu-ppc64le-static flags: offset 0 magic 7f454c4602010100000000000000000002001500 mask ffffffffffffff00fffffffffffffffffeffff00

The above indicates that any ppc64le binary (magic – 7f454c460….) will be executed with /usr/bin/qemu-ppc64le-static.

The magic string is the information encoded in the header of the binary. You can use ‘readelf’ command to check the header of the binary:

# readelf -h <ppc64le_binary> ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) [snip]

Run Power (ppc64le) Docker Images on Intel

On completion of the setup steps, running Power docker images on Intel is as simple as executing the following commands:

# docker run ppc64le/busybox uname -a Or # docker run -it ppc64le/ubuntu <Get a shell and do your work>

Build ppc64le docker images on Intel

Enable docker ‘platform’ experimental flag – https://docs.docker.com/engine/reference/commandline/build/

Build the ppc64le image by executing the following command:

docker build --platform=linux/ppc64le -t <image-tag> .

As you can see multi-architecture development has been made so easy on Linux systems with Qemu and containers.