Contents

Lets create your first Azure Container Registry

1. Introduction

In this guide I’ll be showing you how to configure your first Azure Container Registry to upload your container images. A Registry is needed if you would like to create custom images and later pull these images from other services to run your containers, these could be any containerized systems, including Kubernetes, Docker, etc. The guide will not go over creating custom images as these will be explained in future guides.

2 Requirements

  • This will all be running on Azure so if you don’t have an account or subscription, you can set up a free trial here https://azure.microsoft.com/en-us/free/ which includes $200 limit for 30 days.

2.1 Installing Azure CLI

In this guide we will be using Azure CLI instead of Cloud Shell. The reason for this is that since we’ll be using Docker to create and push images to the Azure Container Registry it would be best that we have one single location to execute all the commands and steps to prevent confusion.

You can install Azure CLI on Windows, Linux, and Mac OS. Please follow the steps in the link below to install it on your PC. Once installed you can use any terminal available in your OS to run azure commands.

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

2.2 Azure Login.

After installing the Azure CLI, run the following command to Log in to your Azure Subscription. On Windows for example you can use Powershell or command prompt, on Linux/Mac OS you can use Terminal

1
az login

This command will open an Internet Browser automatically and ask you to log in onto Azure with your credentials to authenticate.

Another option to login is to use the option ‘ –use-device-code ‘ which will allow you to authenticate from any device as this command will ask you to open a browser and go to ‘https://microsoft.com/devicelogin’ and enter a code to authenticate. You might also see this prompt without the device code option depending on where you are executing the ‘az login’ command, no need to worry, just follow the steps mentioned.

1
az login --use-device-code

2.3 Installing Docker

Now let’s install Docker. This can be installed as well on Windows, Linux, and Mac OS by following the guide below: https://docs.docker.com/get-docker/

After installing and running docker, you can double check that docker is running by executing below command. If an error is displayed docker is not running and you might want to start it. This command is to list running containers, but since we have nothing currently running then no output will be displayed.

1
docker ps

3 What is an ACR and a container image?

An Azure Container Registry (ACR) is a repository that allows you to store container images to later use with Kubernetes or any container-based application. An ACR can contain multiple different repositories and image versions at a time allowing you to re-deploy between different changes quickly in case you wish to roll back to a previous container image version or upgrade to a newer image. A container image itself is a static file, or set of files/layers, that contain your application code ready for execution. A specific image cannot change once it’s been created, allowing you to deploy and run your application between environments keeping your files constant between them. You can of course update and create updated versions of an image and easily keep track of them by uploading these to your Registry.

4 How to I create an ACR?

The first thing we are going to do is create the Resource Group for your ACR and specify an Azure Region. This is also the region where the ACR will be hosted on. In the example below I’ll be using EastUS.

1
az group create --name MyResourceGroup --location eastus

To create your ACR with a Basic SKU you can run below command. This will also register the Resource Provider in your subscription if it’s not already registered. This should take a few minutes in total.

1
az acr create --resource-group myResourceGroup   --name myregistry4567 --sku Basic	
Note
There are three different ACR SKU Tiers that you can choose from, Basic, Standard, and Premium, more details on these can be found in the link below: https://docs.microsoft.com/en-us/azure/container-registry/container-registry-skus

To authenticate and login to your ACR via the Azure CLI run below command. Do keep your registry name in lowercase.

1
az acr login --name myregistry4567 

5 Uploading a test image.

Now that we have created the ACR and have everything above configured, let’s just pull a simple image and upload it to our ACR.

Open the CLI and run below command to pull a test image, make sure that Docker Desktop is also running.

1
docker pull nginx

In this case we won’t be making any changes to this specific image, so we’ll just tag the same one we downloaded as is and push it to the ACR. More guides will be available soon that will go in more details on how to create custom images using docker. I’ve also added a different tag to the image name. When we pulled nginx the latest image was downloaded, but I would like to upload the test image with a different tag version 0.1 as an example.

1
2
docker tag nginx:latest myregistry4567.azurecr.io/nginx-test:0.1
docker push myregistry4567.azurecr.io/nginx-test:0.1

Example outputs below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
5eb5b503b376: Pull complete
1ae07ab881bd: Pull complete
78091884b7be: Pull complete
091c283c6a66: Pull complete
55de5851019b: Pull complete
b559bad762be: Pull complete
Digest: sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

docker tag nginx:latest myregistry4567.azurecr.io/nginx-test:0.1

docker push myregistry4567.azurecr.io/nginx-test:0.1
The push refers to repository [myregistry4567.azurecr.io/nginx-test]
762b147902c0: Pushed
235e04e3592a: Pushed
6173b6fa63db: Pushed
9a94c4a55fe4: Pushed
9a3a6af98e18: Pushed
7d0ebbe3f5d2: Pushed
0.1: digest: sha256:bb129a712c2431ecce4af8dde831e980373b26368233ef0f3b2bae9e9ec515ee size: 1570

After you have pushed images to your Registry you can access the Azure Portal and head over to your ACR. If you scroll down and click ‘Repositories’ under ‘Services’, you will find the image repositories for the containers that have been uploaded. If you click on the Repository name, you will also find the different versions of these images that you might have pushed.

/acr/repo.png
ACR

If you look at the other options available in the Azure Portal for the ACR, you will see many other options to customize and secure your registry, to use Firewalls to limit access over specific IP/Ranges, and even the option to configure endpoints to other services if you prefer to keep access internal and not accessible over the public Internet. I’ll leave this one for you to investigate if it’s something you might want to set up.

6 Conclusion

You have successfully created a new ACR as well as configured a few tools that allowed you to pull and push images. You can now combine this registry with other services to manager your images. Check out other guides for additional tips and information.