Blog Post

Educator Developer Blog
4 MIN READ

How to Store Docker Images in Azure Container Registry using Azure CLI

BabatundeHammed's avatar
BabatundeHammed
Brass Contributor
Sep 01, 2022

Whether you are a developer building a DevOps Pipeline or an individual user looking for ways to store docker images, this article is the place to start. In this article, I will walk you through the steps you need to take to create an Azure Container Registry (ACR) and deploy a docker image to it.

 

Prerequisites

Before attempting to follow along with this tutorial, make sure you have the following things ready:

  • An Ubuntu Operating System - This tutorial will be using version 22.04 LTS.

  • Docker v20.10.12 is installed on Linux. You can install Docker from the Docker website.

  • An Azure Subscription - You can sign up for a free Azure account if you don’t already have one.

  • Azure CLI - This tutorial will use v2.37.0 on a Linux Machine.

  • Redis v7.0.4 Docker Image is available on Linux.

What is Azure Container Registry?

Azure Container Registry (ACR) is a Microsoft-owned private registry where you can store and manage private docker container images and other related artifacts. Then, these images can be downloaded and utilized for container-based deployments to hosting platforms or for local use.

 

Creating A Resource Group

Once you have installed and configured Azure Command Line Interface (CLI), it will become easy to create a Resource Group using Azure CLI. Resource Groups in Azure is a container that manages multiple resources created on Azure.

 

Open your terminal and type the following command to create a resource Group using the Azure CLI.

az group create --name acr-group --location eastus

Different parameters such –name and –location was set to assign acr-group and eastus as the name and location of the resource group respectively.

You can set additonal parameters when creating a resource group. Check out this link

 

The screenshot below shows that a resource group with the name of acr-group has been created.

 

Creating Azure Container Registry using Azure CLI

Creating a Container Registry in Azure using Azure CLI is very time-efficient. The az acr command creates and manages private registries using Azure Container Registry.

The command below creates a cost-optimized basic registry for beginners learning about Azure Container Registry.

az acr create --resource-group acr-group --name basicacr004 --sku Basic

Check out different Container Registry service tiers using this link

When the Container Registry is created, the terminal will display a JSON output similar to the following.

 

Logging in to Azure Container Registry

You must log in to the container Registry on your Linux machine to allow docker to push and pull images from the container registry.

az acr login --name basicacr004

A message will appear in the terminal stating that the login was successful.

 

Tagging Docker Image

You now know how to make a simple Container Registry and log in, but the Container Registry doesn’t yet include any Docker images.

Pushing a Docker image to a remote private container registry is the next action to take. But first, you need to tag a docker image with the fully qualified name of the login server for the registry.

 

A Redis image with version 7.0.4 pulled from DockerHub will be tagged and pushed to the azure container registry.
Learn how to pull Redis image using docker command here.

After pulling the image, you can tag it with the fully qualified name of the login server for the registry. The format of the fully qualified name is <registry-name>.azurecr.io.

docker tag redis:7.0.4 basicacr004.azurecr.io/redis:7.0.4

In the above command, the redis image is tagged with the fully qualified name of the login server for this tutorial registry.

 

Pushing Docker Image to Azure Container Registry

The Redis image has been tagged with the qualified container registry server name. The tagged image can be pushed to Azure Container Registry using the docker command below.

docker push basicacr004.azurecr.io/redis:7.0.4

How do you know that the Redis image has been uploaded to the container registry? The following command will list the images stored inside the container registry in a table format.

az acr repository list --name basicacr004 --output table

 

Conclusion

You should now know how to create an Azure Container Registry (ACR) and push a Docker image to it using Azure Command Line Interface (CLI). Even though there are many ways to do this, this tutorial helped you get started with Azure Container Registry. Eager to learn more on Docker and Azure Container Registry? The learn modules below will help you get going: 

 

What are the next steps? You can deploy more Docker images to the Azure Container Registry.

Updated Sep 01, 2022
Version 1.0
No CommentsBe the first to comment