Docker multi-platform builds
Ever been chilling at work or lounging at home when ping—a message pops up: 'Hey, it’s Bob! I just tried to set up the project on my brand-new, shiny M3 Mac (or whatever number they're at now), and it won’t run on my machine. The error says it wants X but got Y.’ Oh, I bet you’ve been there. Yep, it’s your old frenemy AMD vs. ARM, duking it out over how things should be processed. But never fear Docker is here!
What are multi-platform builds?
Docker multi-platform builds allow you to create your image and it'll work on multiple different platforms. Who doesn’t want their image to be a social butterfly that plays nicely wherever it lands?
Here's how to enable multi-platform builds on your Docker Desktop!
Head over to Settings, make sure you're on the General tab, and check the option for Use containerd for pulling and storing images. Once you've restarted Docker Desktop and the change is applied, you might temporarily lose access to the images and containers from the previous image store. Don’t worry—they're still there! To access them again, just uncheck the option we enabled and restart Docker.
So, this means making sure every user’s machine in your company has this enabled and probably adding it to the company wiki in the start-up guide. But let’s be real—what’s the bet Bob still pings you with the same old 'It's not working!'? Because, you know, 'Ain't Nobody Got Time For That' – Sweet Brown.
CI/CD to the rescue!
This process should work for any CI/CD setup or centralized repository store for your Docker images, but for this example, I’ll be using good old GitLab!
variables:
DOCKER_DRIVER: overlay2
stages:
- build
docker-build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- echo "${CI_REGISTRY_PASSWORD}" | docker login myregistry.com -u "${CI_REGISTRY_USER}" --password-stdin
- docker buildx create --use
- docker buildx build --push -t myregistry.com/image-name:latest --platform linux/amd64,linux/arm64 .
This is a huge win! We’ve logged into our private repository, used buildx, and can now build our image for multiple platforms without needing a bunch of different machines. Now, our users can download the image from myregistry.com/image-name and—bam!—Bob is finally quiet. Adios, Bob!