Build and push docker image to Azure Container Registry

In this blog , We will see how can we build app using docker image and push docker image to Azure Container Registry.

Prerequisite : Build docker image locally by following the steps from Step1 to Step 8.

Step-1 Create Azure Container Registry from Azure Portal.

  • Go to Services -> Container Registries
  • Click on Add
  • Subscription: Free Trial
  • Resource Group: aks-res
  • Registry Name: acrkubdemo (NAME should be unique across Azure Cloud)
  • Location: South EastAsia
  • SKU: Basic (Pricing Note: $0.167 per day)
  • Click on Review + Create
  • Click on Create

Step-2 Build Docker Image Locally . We are going to use same docker image which we have built in our previous blog -

docker build --tag asif1202/demodocker:v2 .

Step-3 Now let’s run the image locally and verify .

docker run --name v2 -p 80:80 asif1202/demodocker:v2

Step-4 – Enable Docker Login for ACR Repository . Goto newly created Container Registry -> Access Keys and enable admin user to push local docker image to docker registry using admin user credentials.

Step-5 – Push Docker Image to ACR . First let’s export ACR image name ,version and namespace and verify .

# Export Command
export ACR_NAMESPACE=app1
export ACR_IMAGE_NAME=demodocker
export ACR_IMAGE_TAG=v2

Step-6 – Login to ACR with given credentials

docker login $ACR_REGISTRY

Step-7 – Now the local docker build image to ACR image.

docker tag asif1202/demodocker:v2 $ACR_REGISTRY/$ACR_NAMESPACE/$ACR_IMAGE_NAME:$ACR_IMAGE_TAG

Step-8– Verify your docker images

# List Docker Images to verify
docker images asif1202/demodocker:v2

Step-9 Push Docker Images


Step-10 -Verify Docker Image in ACR Repository

  • Go to Services -> Container Registries -> acrkubedemo
  • Go to Repositories -> app1/demodocker

Leave a Reply

Your email address will not be published. Required fields are marked *