What is Docker buildx and why it is so important?

“Build once, deploy anywhere” sounds great on paper, but if you want to save money by leveraging ARM targets like the ones found on AWS EKS, or even stick with your old i386 servers, deploying everywhere might be a challenge because you’ll have to create builds specific for these platforms. Docker developed the notion of multi-arch builds to solve this problem, the solution is buildx when building your image.

To elaborate a bit on what the issue is, is that let’s say you are building your Docker images on your local machine and everything works fine. You then push the container to ECS registry or DockerHub and you then go to deploy that special built container within your cluster. For some reason it does not work and you scratch your head as to why. The reason might very well be that the underlying architecture of you cloud cluster does not support the build architecture that you created your container in. I know it took me a while to get to the bottom of all of this and it was hard to navigate what I needed to do.

What you need to do is when you build your image you need to use buildx not build for example:

#### Build the Docker Image for amd64
docker buildx build --platform linux/amd64 --pull --no-cache --rm -f "Dockerfile" -t name_of_your_image:latest "."

Let’s break this command line down a bit, the key parts are “buildx” which means this is not a basic build request and this statement “–platform linux/amd64” is telling Docker to build this container so that it can run on a linux/amd64 machine (standard AWS EKS EC2’s).