Multi-Architecture Docker Image

Ink Insight 🧘🏼
ILLUMINATION
Published in
3 min readDec 30, 2023

Creating Platform Independent Docker Image

Today, we’re diving into the creation of multi-architecture Docker Images.

In the last 1–2 years, organizations have been leaning towards running container workloads on both ARM and AMD architectures. Developing Docker Images that work across different platforms has become crucial.

Here’s a simple guide to building multi-arch images using buildx and Docker Desktop on your local machine:

Step 1: Check if Your Image is Multi-Arch

Verify if your existing image is multi-arch or single arch. Run either of the following commands:

docker manifest inspect -v <docker_image_name> Or,

docker image inspect <docker_image_name> -f "{{ .Architecture}}"

iamu@whoami:~$ docker image inspect controlftp/vmg:v13 -f "{{ .Architecture }}"
amd64

Step 2: Build Multi-Arch Image

Prerequisites:

  • docker buildx install [ installation steps https://github.com/docker/buildx ]
  • Whether you’re using DockerD, Colima, Buildkit, or another tool of your choice, the process is similar.

Building Multi-Arch Docker Image Using buildx

To create multi-arch Docker Images with docker buildx, you’ll need a builder. This builder handles the task of building Docker Images for different computer architectures. Setting up a new builder is a breeze -- just follow these steps:

docker buildx create --name <builder-name> -- bootstrap --use

iamu@whoami:~$ docker buildx create --name multiarch --bootstrap --use
[+] Building 4.9s (1/1) FINISHED
=> [internal] booting buildkit 4.9s
=> => pulling image moby/buildkit:buildx-stable-1 2.8s
=> => creating container buildx_buildkit_multiarch0 2.1s
multiarch

> docker buildx ls [To list the builder and make sure it’s active and running]

iamu@whoami:~$ docker buildx inspect multiarch
Name: multiarch
Driver: docker-container
Last Activity: 2023-12-24 11:50:15 +0000 UTC

Nodes:
Name: multiarch0
Endpoint: unix:///var/run/docker.sock
Status: running
Buildkit: v0.12.4
Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/mips64le, linux/mips64, linux/arm/v7, linux/arm/v6

Now that the builder is ready, and you know the supported platforms, you can use the following command to build your Docker Image for specific architectures (e.g., linux/arm64 and linux/amd64):

iamu@whoami:~$ docker buildx build --push \
--platform linux/arm64,linux/amd64 \
--tag controlftp/vmg:v14 \
.

By including the “--push” flag, Docker will automatically push your Docker Images to Docker Hub. Make sure you’ve authenticated your DockerHub account.

Docker Repo Image: Attached by Author

By default, when pulling your multi-arch image on an AMD-based machine, it will retrieve the AMD version. Similarly, on an ARM-based machine, it will pull the ARM version.

You can modify this behavior by using the “--platform” flag. For instance, to pull an ARM image on an amd64-based machine, you can use the following command:

iamu@whoami:~$ docker pull controlftp/vmg:v14 --platform linux/arm64
v14: Pulling from controlftp/vmg
2c03dbb20264: Pull complete
97fd699e2e27: Pull complete
0e35b4b0e91e: Pull complete
Digest: sha256:0c032f7fd189036ccd9a9d7314cdea90fbb8c96b022d37d58786aab94f04eb9b
Status: Downloaded newer image for controlftp/vmg:v14
docker.io/controlftp/vmg:v14

What's Next?
View summary of image vulnerabilities and recommendations → docker scout quickview controlftp/vmg:v14

iamu@whoami:~$ docker image inspect controlftp/vmg:v14 -f "{{ .Architecture }}"
arm64

Summary:

Building multi-arch image with buildx and docker desktop in your local machine is very simple and straight-forward:

  • Validate if your existing image is multi-arch or single arch image.
  • Create builder using buildx
  • Build and push multi-arch image with docker buildx build — platform linux/arm64,linux/amd64 …

Thanks for reading! I’d appreciate your support 👏 and engagement 🚙 in my stories :)

--

--

Ink Insight 🧘🏼
ILLUMINATION

Discover the intersection of DevOps, InfoSec, and mindfulness with Ink Insight. Follow for valuable insights! ✍︎ 👨‍💻 🧘🏼