Build Multi-Platform Docker Images
Containers share the host kernel, which means that the code that’s running inside the container must be compatible with the host’s architecture. This is why you can’t run a linux/amd64
container on an arm64 host (without using emulation), or a Windows container on a Linux host.
Multi-platform builds solve this problem by packaging multiple variants of the same application into a single image. This enables you to run the same image on different types of hardware, such as development machines running x86-64 or ARM-based Amazon EC2 instances in the cloud, without the need for emulation.
Using a custom builder to build a multi-platform Docker image
Creating a custom builder that uses a driver with multi-platform support, such as the docker-container
driver, will let you build multi-platform images without switching to a different image store. However, you still won’t be able to load the multi-platform images you build into your Docker Engine image store. But you can push them to a container registry directly with docker build --push
.
1. To create a custom builder, use the docker buildx create
command to create a builder that uses the docker-container
driver.
docker buildx create \ |
2. Build and push an image to a container registry
docker build \ |
- The format of IMAGE_NAME:
<dockerhub_username>/<application_name>:<tag>