Building Multi-Arch Images for Arm and x86 with Docker Desktop
Building Multi-Arch Images for Arm and x86 with Docker Desktop
If you don’t already have Docker Desktop, start by downloading it. Install it by following the installation instructions. Once installed, or if you already have Docker Desktop, you should see the Docker icon in your task tray, click preferences, click the Docker Engine
section. Then edit the experimental
option to true.
Get Building
By now I am sure you are interested in how to use these great new features. Let’s take a quick look at some examples. We will start by listing our builders.
○ → docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS PLATFORMS
default * docker
default default running linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6
We are currently using the default builder, which is basically the old builder. Let’s create a new builder, which gives us access to some new multi-arch features.
○ → docker buildx create --name mybuilder
mybuilder
○ → docker buildx use mybuilder
○ → docker buildx inspect --bootstrap
[+] Building 15.4s (1/1) FINISHED
=> [internal] booting buildkit 15.4s
=> => pulling image moby/buildkit:buildx-stable-1 14.7s
=> => creating container buildx_buildkit_mybuilder0 0.7s
Name: mybuilder
Driver: docker-container
Nodes:
Name: mybuilder0
Endpoint: unix:///var/run/docker.sock
Status: running
Platforms: linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6
Here I created a new builder instance with the name mybuilder, switched to it, and inspected it. Note that --bootstrap
isn’t needed, it just starts the build container immediately. Now you can build multi-arch images, the big change from the normal build is the syntax docker buildx build .
.
To build a multi-arch image, you need to add the platform tag with the architectures you want to build for. like this
docker buildx build --push \
--tag mhzawadi/phpmyadmin:5.0.4.0 \
--platform linux/amd64,linux/arm/v7,linux/arm64 .
That worked well! The --platform flag told buildx to generate Linux images for Intel 64-bit, Arm 32-bit, and Arm 64-bit architectures. The --push flag generates a multi-arch manifest and pushes all the images to Docker Hub. Let’s use imagetools to inspect what we did.
○ → docker buildx imagetools inspect mhzawadi/phpmyadmin:5.0.4.0
Name: docker.io/mhzawadi/phpmyadmin:5.0.4.0
MediaType: application/vnd.docker.distribution.manifest.list.v2+json
Digest: sha256:c3735928f4b318b018a28a4f0007b460d840cd9ec8c29c9f316a29da6d241d76
Manifests:
Name: docker.io/mhzawadi/phpmyadmin:5.0.4.0@sha256:4c7e191511aaf9f40be3b6a9b104a349b472e71dea1b99d097b99c36afbd0820
MediaType: application/vnd.docker.distribution.manifest.v2+json
Platform: linux/amd64
Name: docker.io/mhzawadi/phpmyadmin:5.0.4.0@sha256:e9711a221c9b03c0d0009a2fa6ae45292d6f6e1a3823ccb96fe71a91feb35379
MediaType: application/vnd.docker.distribution.manifest.v2+json
Platform: linux/arm/v7
Name: docker.io/mhzawadi/phpmyadmin:5.0.4.0@sha256:9c35a4d52f02dd53b8d846932946526ba5c4754066f35325e91a60d1ea8eb8b2
MediaType: application/vnd.docker.distribution.manifest.v2+json
Platform: linux/arm64
The image is now available on Docker Hub with the tag mhzawadi/phpmyadmin:5.0.4.0. You can run a container from that image on Intel laptops, Amazon EC2 A1 instances, Raspberry Pis, and more. Docker pulls the correct image for the current architecture, so Raspberry Pis run the 32-bit Arm version and EC2 A1 instances run 64-bit Arm.
Published:
by Matt Horwood