The purpose of this repository is to share how to generate and publish Docker images to Docker Hub for various architectures.
Since Apple's New silicon chip doesn't share the default Intel chips architecture, it has an impact on how Docker is run and is used in the new Mac M1 and M2 machines.
To distribute Docker images that can generate containers on both architectures, I have compiled on this repository two methods for building either Docker images from a Dockerfile that use BuildKit (1, 2, 3).
-
Method one: GitHub Action (4)
-
Method two: Docker commands (5).
Adapted from (4)
The GitHub Action workflow build and pushes direct to DockerHub the two Docker images. There are some requirements:
- The base image should exist in both architectures
arm64
andamd64
. - There are two SECRETS to add to the GitHub repository:
DOCKER_USERNAME
,DOCKER_PASSWORD
.
Adapted from (5)
You should have Docker Desktop installed.
docker buildx create --name=mybuilder --use
docker buildx inspect --boostrap # extra
docker ps # extra
docker buildx build -t username/image --platform linux/amd64,linux/arm64 --push . # If you are running the command in the folder where the Dockerfile is
Note
In case of getting the following error run docker login --username=<username>
------
> exporting to image:
------
error: failed to solve: server message: insufficient_scope: authorization failed
For more details read 6.
1 - Building Multi-Arch Images for Arm and x86 with Docker Desktop (2019) - Adam Parco
2 - Multi-Platform Docker Builds (2020) - Adrian Mouat
3 - How to Rapidly Build Multi-Architecture Images with Buildx (2022) - Tyler Charboneau
4 - Building multi-architecture images with GitHub Actions (2020) - Lars Kellogg-Stedman
5 - DockerCon 2021: I Have an M1 Mac, Now What? Docker in a Multi-arch World - Tonis Tiigi
6 - Multi-platform images - Docker documentation