Multi-Platform Image Building - docker/buildx

Multi-Platform Image Building with Buildx

Buildx is a Docker CLI plugin that extends the docker build command with complete support for BuildKit’s feature set, enabling faster multi-platform builds. It comes packaged with Docker Desktop and can be used with the docker buildx command in Linux environments.

Emulation

One way to build images for other platforms is to emulate the target platform using QEMU. With the recent Buildx work, it’s easier than ever to use QEMU with Docker.

QEMU Emulation

QEMU is a fantastic project that can emulate a whole bunch of platforms. With Buildx, you can use QEMU to emulate different platforms and build images for them.

Example:

docker buildx build --platform linux/arm64 -t my-image:arm64 .

Source: Multi-Platform Docker Builds | Docker

Cross-Compilation

Another option is to cross-compile the images for different platforms. Buildx supports cross-compilation with the --platform flag.

Example:

docker buildx build --platform linux/arm64 -t my-image:arm64 .

Source: Faster Multi-Platform Builds: Dockerfile Cross-Compilation Guide | Docker

Multi-Platform Images

Multi-platform images are supported for .Image, .SLSA, and .SBOM fields. You can pick up a specific platform using the index Go template function.

Example:

docker buildx imagetools inspect --format '{{json (index .Image "linux/s390x")}}' moby/buildkit:master

Source: docker buildx imagetools inspect | Docker Docs

Multi-Arch Images

Buildx allows you to build multi-arch images, link them together with a manifest file, and push them all to a registry with a single command.

Example:

docker buildx build --platform linux/amd64,linux/arm64 -t my-image:latest .

Source: Building Multi-Arch Images for Arm and x86 with Docker Desktop | Docker

Creating a Builder

Creating a custom builder allows you to control what buildpacks are used and what image apps are based on.

Example:

  1. Create a builder.toml file:
# Builder configuration

[[buildpacks]]
uri = "samples/buildpacks/hello-processes"

[[buildpacks]]
uri = "docker://cnbs/sample-package:hello-universe"
  1. Build the builder:
docker buildx create --use

Source: Create a builder · Cloud Native Buildpacks

Multi-Platform Builds with werf

werf can build images for either the native host platform or for arbitrary platforms in cross-platform mode using emulation. It is also possible to build images for multiple target platforms at once (i.e. manifest-list images).

Example:

werf build --platform linux/arm64

Source: Multi-platform and cross-platform building | werf