Build with buildx

buildx is a CLI tool that provides a user interface for working with builds. Buildx is a drop-in replacement for the legacy build client used in earlier versions of Docker Engine and Docker Desktop. In newer versions of Docker Desktop and Docker Engine, you’re using Buildx by default when you invoke the docker build command. In earlier versions, to build using Buildx you would use the docker buildx build command.

As of Docker Engine 23.0 and Docker Desktop 4.19, Buildx is the default build client.

One of the most important features of Buildx is the ability to build multi-platform images. You can create arm64 and amd64 images in one build and push them to the same repository.

You can read more about buildx in official documentation.

Create builder

First you need to create builder:

docker buildx create --use --platform=linux/arm64,linux/amd64 --name multi-platform-builder
docker buildx use multi-platform-builder

then you can check if it is active:

docker buildx inspect --bootstrap
docker buildx ls # check if multi-platform-builder is active

Build multiplatform image

The following example shows how to build multiplatform image from Dockerfile:

docker buildx build \
    --platform=linux/arm64,linux/amd64 \
    --tag container:bookworm \
    --tag container:latest \
    --no-cache \
    --push .