Docker Cross CPU architecture builds with Travis CI and buildx

Quentin McGaw
1 min readNov 25, 2019

--

After months of headaches, I finally found the way to do Docker images for all CPU architectures automatically. This article is for Travis CI, but it works very similarly on other CIs.

Why

It turns out many people like to run Docker containers on all kind of machines, and these can have different CPU architectures than most amd64 computers. I’m especially looking at you, Raspberry Pis…

End result

  • One Docker image built per CPU architecture (7 total)
  • Image size is the same as if it would be built natively on the corresponding CPU architecture
  • Pull :latest or any custom tag and it will pull the right image for your architecture automatically

Requirements

  • You need a repository, for example on Github
  • Turn on Travis CI for that repository here
  • Have some kind of Dockerfile

Setup

Create a .travis.yml file with (also change <DOCKER_USER/DOCKER_IMAGE>):

and create a ci.sh script file with:

Finally, in your Travis settings for that repository, set an environment variable DOCKER_PASSWORD with your docker hub password as value, only available to the master branch.

Details

We use docker’s experimental build command, buildx, to build the Docker images for all architectures. We also use QEMU to be able to executeRUN Docker instructions for another architecture although our host system is amd64.

This results in all Docker images being pushed to Docker Hub together with a manifest file tagging each image for the right architecture. Tadaaaa!

Enjoy!

--

--