docker azure-min.png
Cover image for kevinblanco

Kevin Blanco Verified userVerified user

Senior DevRel Advocate

Appsmith

Pushing a Docker Image to Azure Container Registry

Goal

At the end of this article, you'll have a docker image pushed to the Azure Container Registry so you can then use it to host your application in Azure Container Instances (ACI), which is a simple and efficient way to run containers in the cloud

Prerequisites

Overview

Over the last few weeks (starting July 2024), engineers trying to deploy a container to Azure referencing a Docker image from Docker hub (docker.io, or index.docker.io) started to face the following error (read more in this issue) preventing them to deploy an Azure Container 

az container create throwing ERROR: (RegistryErrorResponse) An error response is received from the docker registry 'index.docker.io'. Please retry later.

The reason is because Docker Hub is rate limiting the Azure IPs, and while this might be fixed if you wait, this can continue to happen from time to time. One solution is to pass your docker hub API key or credentials as flags when deploying, but this is not secure neither substainable. The best and easiest way is to push your image to the Azure Container Registry and use that when deploying your cointainers. 

  1. Setup your Azure CLI

    On your preferred terminal, login to the Azure CLI and select your Azure Container Registry

    az login
    az acr login --name myregistry

    How do you know what your registry name is, or how to create your registry in case you don't have one? Very easy: 

    Find Container Registry on the Azure search bar, and there you will see your Registry name or click on the "Create" button 

    azure container registry

    Once created, you can use that name to log in, and also, your server name will be name.azurecr.io. In my case, my Registry name is appsmith so my server name is appsmith.azurecr.io, we'll need that value in the next step! 

  2. Pull and Push your Image

    Now fully authenticated to Azure and with a Registry to push, let's pull the docker image you want to push from Docker Hub to Azure. In my case, I want to pull the Appsmith Enterprise Edition, whose Docker URL is index.docker.io/appsmith/appsmith-ee so let's run: 

    docker pull index.docker.io/appsmith/appsmith-ee

    When that's done, we can tag our image for Azure running: 

    docker tag appsmith/appsmith-ee:latest appsmith.azurecr.io/appsmith-ee

    Now tagged, we can push it to Azure! 

    docker push appsmith.azurecr.io/appsmith-ee

    And that's it! 

    Now, if we run: 

    az acr repository list --name appsmith.azurecr.io

    and we'll get something like this: 

    [
      "appsmith-ee"
    ]

    Remember to use your server name in those commands, in my case is appsmith.azurecr.io, but your case will be different! 

    Now you can deploy your own instance container using that tag as your image, for example: 

    az container create \
    	--resource-group $resourceGroupName \
    	--name $aciName \
    	--image appsmith.azurecr.io/appsmith-ee \
    	--ip-address public \
    	--ports 80 443 \
    	--cpu 2 \
    	--memory 4 \

Conclusion

While you might find workarounds online, the best way to deploy Docker images to your Azure containers is to push them to your Registry, this will give you more control, security and consistent results. 

Additional Resources