DEV Community

Thiago (Zozô) Ozores
Thiago (Zozô) Ozores

Posted on • Originally published at ozor.es on

Building multiarch images with Buildah

With the growth and popularization of platforms beyond amd64, especially the ARM platform, it becomes a concern for those maintaining container images to build them tailored for these platforms as well.

In this article, I will show you how to build these images using Buildah.

Buildah is an open-source project led by RedHat (but receives contributions from other companies) that aims to simplify the construction of container images that adhere to and are compatible with the OCI (Open Container Initiative) standard.

So let’s get to the steps.

Prerequisites

  • Installation of the Buildah package
  • Installation of the qemu-user-static package (Ubuntu/RedHat) or qemu-arch-extra package (Arch Linux);

sudo dnf install -y buildah qemu-user-static (Fedora and derivatives)

sudo apt-get install -y buildah qemu-user-static (Ubuntu/Debian and derivatives)

pacman -Sy buildah qemu-arch-extra (Arch Linux and derivatives)

Building the images

The workflow you need to follow to build the images is as follows:

  1. Create the manifest
export MANIFEST="multiarch-image" # manifest name, can be any name
export IMAGE="registry/repository/image:tag" # image name, e.g., docker.io/ozorest/example:latest
buildah manifest create "$MANIFEST"

Enter fullscreen mode Exit fullscreen mode
  1. Run the build for each architecture

In the directory with your Dockerfile, you can run the following loop for each architecture:

for arch in amd64 arm64; do
 buildah build --arch $arch --tag "$IMAGE" --manifest "$MANIFEST" .
 # buildah build --arch $arch --tag "$IMAGE" --manifest "$MANIFEST" -f path_to_Dockerfile, in case the Dockerfile is not in the current directory
done

Enter fullscreen mode Exit fullscreen mode
  1. Push the manifest to the registry
buildah manifest push --all "$MANIFEST" "docker://$IMAGE"

Enter fullscreen mode Exit fullscreen mode

And that’s it, folks! Stay tuned for more content!

Top comments (0)