Building and Pushing Docker Images from Mac M1 to Azure Container Registry: A Complete Guide

Aayush PaigwarAayush Paigwar
3 min read

Introduction:

In today's rapidly evolving tech landscape, developers often find themselves working across various platforms and architectures. With the rise of ARM-based Macs like the M1, ensuring compatibility and smooth deployment to cloud services such as Azure Container Registry (ACR) becomes essential. In this blog post, we'll explore how to build and push Docker images from a Mac M1 to ACR seamlessly.

Understanding the Architecture Difference:

Mac M1 systems utilize the ARM64 architecture, while most cloud-based infrastructure runs on x86 architecture. This disparity can lead to compatibility issues when deploying Docker images from Mac M1 to ACR.

Solution:
Leveraging Docker Buildx for Multi-Platform Support. Docker Buildx, a powerful CLI plugin, comes to the rescue by enabling developers to build Docker images for multiple platforms simultaneously. Let's dive into the steps involved:

Step 1: Set Up Docker Buildx Builder Instance

Create a Docker Buildx builder instance using the following command:

docker buildx create --name mybuilder --use

This command initializes a builder instance named "mybuilder" for multi-platform builds.

Step 2: IDE Authentication to Azure Container Registry

Before pushing your image, establish a connection between your ACR and local IDE. Login to ACR using:

az acr login -n <your-acr-name>

Make sure you have enabled the admin user in the Azure Portal under Access keys settings as shown in the image below.

**

Step 3: Building and Pushing Docker Image to ACR:**

Now, let's build and push our Docker image to Azure Container Registry. Execute the following command:

docker buildx build --platform linux/amd64,linux/arm64 -t <acr-name>.azurecr.io/my-image:latest --push .

Explanation of the above command:

  • docker buildx build: Initiates the build process using Docker Buildx.

  • --platform linux/amd64,linux/arm64: Specifies the target platforms for the build.

  • -t <acr-name>.azurecr.io/mac:latest: Tags the resulting image with the specified name and tag.

  • --push . : Pushes the built image to the specified container registry.

Replace <acr-name> with the name of your Azure Container Registry. This command builds a multi-platform image for both x86 and ARM architectures and pushes it to ACR.

How to load the Docker image in Docker Desktop?

After pushing the image to the ACR, the image is stored in the build cache while building it if you want to load the docker image on the docker desktop you can use the following command:


docker buildx build --load -t <your-image-name>:<tag> .

In case of encountering an error shown below.

[+] Building 0.0s (0/0)                               docker:desktop-linux                                                    
ERROR: Multi-platform build is not supported for the docker driver.
Switch to a different driver, or turn on the containerd image store, and try again.
Learn more at https://docs.docker.com/go/build-multi-platform/

Then, try the following commands:


docker buildx rm mybuilder

The above command removes the previously created builder.
Then recreate a builder using:

docker buildx create --name mybuilder --use --driver docker-container

Now, continue from Step 2 onwards.


Conclusion:

Using Docker Buildx makes it easy for developers to create and send Docker images from Mac M1 computers to Azure Container Registry. This method guarantees that your software works smoothly on different types of computer systems, making it easier to deploy without running into compatibility issues. Embracing this multi-platform approach is crucial for managing the complexities of today's software development and deployment.

10
Subscribe to my newsletter

Read articles from Aayush Paigwar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Aayush Paigwar
Aayush Paigwar

I am a Flutter Developer and UI/UX Designer with some knowledge of Machine Learning and Deep Learning and a beginner in Web Development