Multi-arch Building with Docker

Building an aarch64 Image on x86_64 Linux

First, make sure you’ve got a Docker CE version >= 21.0 installed:

➜  ~ docker --version
Docker version 24.0.7-ce, build 311b9ff0aa93

Install Docker Buildx plugin

Download the latest binary from the GitHub Releases.

wget https://github.com/docker/buildx/releases/download/v0.14.0/buildx-v0.14.0.linux-amd64

Rename the relevant binary and copy it to the destination matching your OS, changing the permissions to make it executable.

mv buildx-v0.14.0.linux-amd64 docker-buildx
cp docker-buildx ~/.docker/cli-plugins/
chmod +x ~/.docker/cli-plugins/docker-buildx

Building with QEMU

QEMU is the easiest way to get started if your node already supports it (for example. if you are using Docker Desktop). It requires no changes to your Dockerfile and BuildKit automatically detects the secondary architectures that are available. When BuildKit needs to run a binary for a different architecture, it automatically loads it through a binary registered in the binfmt_misc handler.

➜  ~ docker run --privileged --rm tonistiigi/binfmt --install all
Unable to find image 'tonistiigi/binfmt:latest' locally
latest: Pulling from tonistiigi/binfmt
8d4d64c318a5: Pull complete
e9c608ddc3cb: Pull complete
Digest: sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55
Status: Downloaded newer image for tonistiigi/binfmt:latest
installing: arm64 OK
installing: mips64le OK
installing: mips64 OK
installing: arm OK
installing: s390x OK
installing: ppc64le OK
installing: riscv64 OK
{
  "supported": [
    "linux/amd64",
    "linux/arm64",
    "linux/riscv64",
    "linux/ppc64le",
    "linux/s390x",
    "linux/386",
    "linux/mips64le",
    "linux/mips64",
    "linux/arm/v7",
    "linux/arm/v6"
  ],
  "emulators": [
    "qemu-aarch64",
    "qemu-arm",
    "qemu-mips64",
    "qemu-mips64el",
    "qemu-ppc64le",
    "qemu-riscv64",
    "qemu-s390x"
  ]
}

Building with docker-compose

aarch64 example
COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
DOCKER_DEFAULT_PLATFORM=linux/arm64 \
docker-compose build \
        --no-cache \
        --progress plain \
        --build-arg hpe_github_token=${HPE_GITHUB_TOKEN} \
        --build-arg dkms_only=${DKMS_ONLY} \
        --build-arg kernel_version=${KERNEL_VERSION} \
        --build-arg lustre_refspec=${LUSTRE_REFSPEC} \
        --build-arg mofed_version=${MOFED_VERSION} \
        --build-arg nvidia_driver_version=${NVIDIA_DRIVER_VERSION} \
        --build-arg nvidia_fs_version=${NVIDIA_FS_VERSION} \
        ${OS_VERSION}
x86_64 example
COMPOSE_DOCKER_CLI_BUILD=1 \
DOCKER_BUILDKIT=1 \
DOCKER_DEFAULT_PLATFORM=linux/amd64 \
docker-compose build \
        --no-cache \
        --progress plain \
        --build-arg hpe_github_token=${HPE_GITHUB_TOKEN} \
        --build-arg dkms_only=${DKMS_ONLY} \
        --build-arg kernel_version=${KERNEL_VERSION} \
        --build-arg lustre_refspec=${LUSTRE_REFSPEC} \
        --build-arg mofed_version=${MOFED_VERSION} \
        --build-arg nvidia_driver_version=${NVIDIA_DRIVER_VERSION} \
        --build-arg nvidia_fs_version=${NVIDIA_FS_VERSION} \
        ${OS_VERSION}