This post is just a short summary on how to use buildah
to build multi-architecture containers.
Building multi-architecture containers (e.g. x86_64
and arm64
) is an easy task using docker buildx
, e.g.
docker buildx build --platform linux/amd64,linux/arm64 -t feldspaten.org/my-multi-arch-container
However, the buildx
command does not exists in podman
natively. Here buildah
can be used in conjunction with OCI image manifests and image indices.
Image manifest can reference platform-specific versions of an image. Since I didn’t got all the details yet, let’s for now just start with how you can use buildah
to create multi-platform containers, shall we?
Pre-requirements
buildah
(duh!) - comes typically withpodman
qemu
packages for the desired target architecture
For the qemu
packages, ensure that e.g. qemu-aarch64
is installed. On openSUSE Tumbleweed the following might give you a good selection
zypper in qemu-arm qemu-extra
Building
The workflow you need to follow is the following:
- Create a manifest
- Build for your desired architectures
- Push the manifest to the registry
# Manifest name, can be anything
export MANIFEST="myapp-multiarch"
# Where to push to
export IMAGE="ghcr.io/user/image:v1.0.0"
# Create manifest
buildah manifest create "$MANIFEST"
## Add here your architectures. One build per architecture
# Build container for amd64 (x86_64) and arm64 (aarch64). Add more architectures as needed
buildah build --arch amd64 --tag "$IMAGE" --manifest "$MANIFEST" .
buildah build --arch arm64 --tag "$IMAGE" --manifest "$MANIFEST" .
# Push the manifest, this will include all architectures you build for before
buildah manifest push --all "$MANIFEST" "docker://$IMAGE"
And that’s it. Using this process you should be able to build and push a custom multi-arch OCI container using buildah