Build and Push Image to Azure Container Registry : Practical Implementation

Filed Under: Random
Build And Push Images To ACR

Hello readers! This article talks about the way to Build and Push Docker Images to Azure Container Registry with a practical demonstration.

So, let us begin!!

Quick Recap – Dockerfile and Docker Images

With the increasing demand and supply chain in every sector, it is important for any business/technology product to be able to scale with the increasing demands.

Relating it to the cloud world, we have seen the transition right from on-premise servers to Virtual Machines. And, now we are here with a more packaged way of scalability with Containers. Containers enable us to encapsulate every aspect and library (configuration files) for an application to run efficiently. Thus, it has led to introducing more scalability in the application/product with cost optimization.

To benefit from containers, we need to start building the Dockerfile. It is the configuration file that consists of all the instructions to feed the application for it to run in the form of a container.

Once the Dockerfile is ready, we build a Docker image out of it. The Docker Image is a blueprint of the entire application execution process.

In order to roll out a container, we need to provision the Docker Image to store in some Registry. It can be a public registry like the Docker Hub or a private one like the Google Container Registry (GCR) or the Azure Container Registry (ACR).

Private container registries tend to be a more secure place for our Docker Image as the image is the blueprint of the entire product and it is not feasible to be compromised under any circumstance. In order to use an image from a private registry, we need to authenticate the service account/ Service Principle and use Image pull secrets in the Kubernetes Deployment YAML file.

In this article, we will be focusing on Pushing the image to Azure Container Registry.

Build and Push Docker Image to Container Registry – Steps

Let us now begin the process to build and push a Docker Image to ACR. Below are the steps to push an Image to a Container Registry-

  • Create a Dockerfile
  • Provision a Docker Image
  • Authenticate with the Azure Container Registry
  • Tag the Docker Image
  • Push the Image to ACR

Step 1: Create a Dockerfile

The Dockerfile should include all the configuration files/libraries that are needed to run the application/product.

Have a look at the below Dockerfile-

FROM python:alpine3.12

RUN curl -LO | bash \ && chmod +x ./kubectl \ && mv ./kubectl /usr/local/bin/kubectl 

RUN curl > /tmp/google-cloud-sdk.tar.gz

WORKDIR /usr/src/application
COPY . .
ADD /usr/src/application

ENTRYPOINT ["python3",""]

This is a demo Dockerfile that is built over the base python-alpine image. It also contains commands/instructions to install some packages such as gcloud, kubectl, etc during the application execution.

Step 2: Provision a Docker Image

Having created a Dockerfile, it is time to build an Image to over it using the below command-

docker build -t image_name:tag .

Once the image is built, you can find it locally on your system using the below command-

docker images

Demo Output:

Docker Images

Step 3: Authenticate with the Azure Container Registry

In order to push Images to ACR, we need to set up a Container Registry within the Azure Subscription.

Image 1
Create an Azure Container Registry

Once the container registry is ready, we can view it under the resource group within the subscription of Azure as seen below-

Image 2

We now need to authenticate ourselves to the subscription which holds the container registry. This can be done using the below commands-

az login
az account set --subscription subscription_ID

At last, we login to the Container registry using the below command-

az acr login --name docsamACR


Image 3
ACR login

Step 4: Tag the Image and push to ACR

We now need to tag the image that we built in Step 2 using the below command-

docker tag hello-world:latest

And as the final step, we need to push the tagged image to ACR.

docker push


Image 4
Docker push
Image 5


By this, we have approached the end of this topic. Feel free to comment below, in case you come across any questions.

For more such posts related to Kubernetes and Docker, Stay tuned with us.

Till then, Happy Learning!! 馃檪

Generic selectors
Exact matches only
Search in title
Search in content