Building Multi-platform Docker Images Natively then Generating a Single Cross-Platform Tagged Image

Whilst Docker buildx can be used in many cases to cross-build images for one architecture platform from another (eg amd64 images from an arm64 platform, or vice versa), I’ve been having problems getting my TM351 image to cross-build for amd64 from my Mac M2 (an arm64 device), or for arm64 from my old amd64 Intel Mac.

docker buildx build -f Dockerfile-custom --platform linux/amd64,linux/arm64 . --tag ousefulcoursecontainers/ou-tm351:23j --push

Whilst the cross-build does seem to work from our institutional GitLab server (I haven’t tried using a GitHub Action), the CI is not using the version of ou-container-builder that I have forked, and it takes a considerable amount of time on the cross-build. The docker buildx cross-build approach works by building each image and pushing the layers as well as a creating a manifest file that associates the two platform specific images with the same docker image tag.

To manually create such an image, we can build each image separately on its native platform, push it to Docker Hub, and then manually create a manifest file for the cross-platform tagged image.

For example, on my new Mac, I might use the following command to build and push the outm351dev/tm351-23cnb:arm64.v1 image: docker build . --tag outm351dev/tm351-23cnb:arm64.v1 --push.

On my old Intel Mac: docker build . --tag outm351dev/tm351-23cnb:amd64.v1 --push.

Then on either machine, I could create and push the manifest file:

docker manifest create outm351dev/tm351-23cnb:23j-test \
    --amend outm351dev/tm351-23cnb:amd64.v1 \
    --amend outm351dev/tm351-23cnb:arm64.v1 

docker manifest push outm351dev/tm351-23cnb:23j-test

Inspect the images on Docker Hub, we see the indiividual, platform specific images, as well as the cross-platform image:

From a simple test, it seems as if you need the same image name (but different tags) for all the images.

See also this related official Docker blog post.

Author: Tony Hirst

I'm a Senior Lecturer at The Open University, with an interest in #opendata policy and practice, as well as general web tinkering...