Buliding ppc64le container on x86_64 machine with Qemu User Static and buildah

Mayur Waghmode
3 min readJul 15, 2021

--

Image credits : https://raw.githubusercontent.com/multiarch/dockerfile/master/logo.jpg

qemu-user-static is a fast processor emulator that uses the current operating system to run other architectures. Currently, the package supports ARM, CRIS, i386, M68k (ColdFire), MicroBlaze, MIPS, PowerPC, ppc64le, SH4, SPARC, and x86–64 emulation.

Buildah is an open-source, Linux-based tool that can build Docker- and Kubernetes-compatible images, and is easy to incorporate into scripts and build pipelines. In addition, Buildah has overlap functionality with Podman, Skopeo, and CRI-O. Buildah has the ability to create a working container from scratch, but also from a pre-existing Dockerfile. Plus, with it not needing a daemon, you’ll never have to worry about Docker daemon issues when building container images.

With the use of Qemu-user-static and Buildah it becomes possible and relatively easy for everybody to build and publish images that work on multiple CPU architectures.

This article aims to build a ppc64le container on an x86_64 machine using qemu-user-static and buildah. The same container image can be used on ppc64le architecture.

Pre-requisites:

This example uses an RHEL 8.4 x86_64 VM.

1. Install Podman and Buildah

dnf install podman buildah

2. Configure podman

Create a file called /etc/containers/registries.conf if one doesn't already exist, and make sure that these lines are inside it:

[registries.search]
registries = ['docker.io']

If your system came with this file, so long as ‘docker.io’ is included in the registries list, you should be okay.

This example uses all the repositories from dockerhub only. If you have multiple registries search list use docker.io to run the remote repository.

3. Run the multiarch qemu-user-static build container

This will enable a few settings to allow running non-native containers.

sudo podman run --rm --privileged multiarch/qemu-user-static --reset -p yes

4. Build a ppc64le container image using buildah on x86 architecture

Dockerfile example

FROM ppc64le/ubuntu:20.04
RUN apt-get update -y
ENTRYPOINT ["/bin/cat","/proc/cpuinfo"]

Build the Dockerfile using buildah

buildah bud -f Dockerfile -t image-name .

Start building a ppc64le container from the image with buildah

container=$(buildah from image-name)

It will create a buildah container based on a Dockerfile, and store the result of this command in the container variable. This is an easy way to avoid learning what the container's name is. If we care, though, we can do this

$ echo "$container"
=> image-name-working-container

Run a command in the container

buildah run $container bash

Now you have a bash shell inside your ppc64le container! Since you have shell access, you can build this system up the same way you would a VM or a bare-metal setup, creating users and installing packages.

Save your container

Now that you’ve spent the time building this container up to do exactly what you need, you need to save it!

buildah commit $container image-name

5. Publish your image

You can log into dockerhub, or another registry with the buildah login command. Once you've got your credentials set up, you can push your images with buildah.

This example uses dockerhub to push the image

buildah login docker.iobuildah push image-name dockerhub_username/repository_name

6. Run your image with Podman

Now that your image is public, you can run it on any ppc64le system with podman or docker

podman run dockerhub_username/repository_name

--

--