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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
To authenticate and login to your ACR via the Azure CLI run below command. Do keep your registry name in lowercase.
|
|
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.
|
|
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.
|
|
Example outputs below.
|
|
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.
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.