Is Multi Platform Build Automation possible?

I’m pretty new to docker hub, and I just set up my first repository, and added an automated build rule from GitHub.

The problem is that when I pull the image to my M1 Mac, I get the following error:
image

From what I can tell, it’s because I’m not building the image with buildx or multi platform support.

Is there a way to do that from DockerHub? Or am I going to have to have some external process for my CI/CD pipeline?

You can’t build multiarch images by default on Docker Hub, but you can use build hooks to do that:

Note that it says it will run your build on Amazon Linux machines which was not true in my case, but I reported this issue on Github

The idea is to create a folder called “hooks”, save your hooks there and use these commands somwhere in those hooks:

docker buildx create --name multiarch --use
docker buildx build . -t <your_image_name> -f Dockerfile --platform linux/arm64/v8,linux/amd64 --push

It will immediately push your images so you can’t run build and push in separate hooks unless you do what I did. I used the build hook to build an image with a one tag, then tested every architecture in a loop in the test hook, and I ran docker buildx again with different parameters where I set new tags following semantic versioning.

You can see environment variables in the documentation. You can use those to tag your image based on the build rules you set on Docker Hub, or you can use completey different tags.

Since it is running in one build process, the second build will use the cache and just tag the images quickly.

The first line in my example is necessary to have an emulated build environment for different platforms.

Thank you for the response.

So, in this case, the images are built on GitHub and pushed to Docker Hub?

Would this be different than, say, disabling Automated builds, and writing a GitHub workflow to do the same?

Have you read the documentation I linked? You don’t need to build on GitHub if you use Automated builds. You can use hooks on Docker Hub. You just need to create them in your git repo.

Yes, because it is your choice whether you want to build on GitHub and push to Docker Hub or do everything on Docker Hub.

There is only one thing I could not solve on Docker Hub and this is scheduled nightly builds for specific branches, so I use CircleCI for that until it is implemented on Docker Hub.

1 Like

Quick follow up, I appreciate that Docker Hub provides the capability to override the default commands using hooks, and for some people that is probably a great solution.

As I dig in a bit more, though, I find (for myself) that using GitHub workflows / actions to do Multiplatform builds is a win for me, as I have one place that controls the entire CI/CD pipeline (including deployment to my web servers).

I found the guide here to be very helpful:

1 Like