Docker Multi-Architecture Images

Let docker figure the correct image to pull for you

In one of the projects I’m working on, we’re targeting both Linux and Windows system. Of course we’re using Docker to containerize the whole application and make it easy to work on both systems: we created two docker images one for each supported system, and after that what we needed was to make sure that if someone would be pulling the my-cool-image:latest from a Unix-based machine, the Linux image would be returned, while if doing the pull from a Windows machine (using Windows containers), then the windows-based image would be used.

yorek/multiarch-hello-world

Create two images

Let’s first of all create two very simple images that will serve two different architectures. Here’s the “Hello World” for Windows:

FROM microsoft/nanoserver:latest
CMD echo "Hello World from Windows"
FROM alpine:latest
CMD echo "Hello World from Linux"

Enable manifest command

Docker now support the ability to work with image manifest natively. The feature is still in development and thus if you just try to run it

docker manifest
docker manifest is only supported when experimental cli features are enabled
{
"experimental": "enabled",
"credsStore": "wincred",
"auths": {
"https://index.docker.io/v1/": {}
}
}

Create a manifest list

The first step to create a multi-architecture image is to create a manifest list. The manifest list will be seen as a “virtual image” but it will actually contain an index of available images with their relative supported architecture. With that information the docker client will now be able to actually pull the image for the correct architecture.

yorek/multiarch-hello-world:latest
  • yorek/multiarch-hello-world:windows
docker manifest create 
yorek/multiarch-hello-world:latest
yorek/multiarch-hello-world:linux
yorek/multiarch-hello-world:windows
docker manifest push yorek/multiarch-hello-world:latest

Inspect a manifest list

Well, you can actually inspect manifest list and manifests for single images. For example if you run

docker manifest inspect yorek/multiarch-hello-world:windows

Want to know more?

If you’re interested in the topic and want to know more, you can start learning from the historical background behind the multi-architecture feature here (thanks @druttka for the link ):

Data Geek, Storyteller, Developer at heart, now infiltrated in Azure SQL product group to make sure developers voice is heard loud and clear. Heavy Metal fan.