Azure - Container Registry: Creation and Pushing Images

azure cloud container docker registry devops

The intention of this post is to show how a Container Registry can be created within the Azure Portal and how Images can be pushed

acr-image-pushed

Introduction

During the last days, I’ve had to provide several Container Images to an Azure Container Registry, making them available for services like Azure Container Instances or Azure Kubernetes Service. The goal of this post is to explain how an Azure Container Registry can be created and used for pushing Images within the Azure Portal. Therefore I’ve created a simple Windows Container, which serves as an example and which is described in the next section.

Example Windows Container serving as Example for being pushed to the Container Registry

The Dockerfile of the corresponding mentioned Example Container can be seen below. The Base Image is a Windows-Server-Core Image. At runtime the Container tries to reach my Webside, which is implemented within a Powershell script “Start.ps1” and terminates afterwards.

FROM mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2019

WORKDIR "C:/Scripts"

ADD "Scripts/Start.ps1" "C:/Scripts"

ENTRYPOINT powershell -File Start.ps1

All related files can be downloaded from GitHub: https://github.com/patkoch/blog-files/tree/master/post6

Creating a Container Registry in Azure Portal

At first, a new Azure Container Registry is created within the Azure Portal. That’s quite easy: simply choose Container Registry at the Container category and trigger the creation of that new resource:

AzurePortal-Create-ContainerRegistry

At the Bascis section, choose your subscription and your resource group. After that, provide a name for the registry of your choice - I’ve named it “patricksregistry”. I’ve used “Germany West Central” as it fits best according my current location - unfortunately there exists no proper Austrian location ;) According to the outstanding sections: I’ve used the proposed settings and quickly finished the creation of the Container Registry.

AzurePortal_Creating_ACR_Basics

The resulting empty Container Registry “patricksregistry” looks like as in the picture below - so there is no Container Image available yet, but we’ll change that within the next sections.

ACR Blank

Pushing an Image to the Container Registry

Storing your Container Image to the Container Registry can be done with following steps:

  1. Login to the Container Registry
  2. Tag your Image so that it fits for the Container Registry
  3. Push your Image to the Container Registry

1. Login to the Container Registry

The proper command for the login to the Container Registry can be done with following command:

docker login <login server> --username <username> --password <password>

Probably the resulting question would be “where to find the credentials?” For that, switch to “Access keys” at “Settings” - there the mandatory credentials for the login procedure can be found:

ACR_AccessKeys

In my case “username” would be “patricksregistry”, password - of course secret and the “Login server” would be “patricksregistry.azurecr.io”.

2. Tag the Image

Apply following command to tag your Container Image properly for the registry:

docker tag <source image id> <target image[:tag]>

https://docs.docker.com/engine/reference/commandline/tag/

The proper value for the target image, including a tag, would be “patricksregistry.azurecr.io/patricksrepo/containerpost06:firstversion”.

3. Push the Image to the Container Registry

That’s of course the popular command for pushing the Container Image:

docker push <target image[:tag]>

Executing those three commands in a sequence looks like as in the picture shown below:

ACR_Login_Push_Image_Finished

Finally, the Container Image should be pushed and stored at the Container Registry.

Switching back to the Azure Portal reveals, that the Container Registry is not empty any more: the Container Image is now stored and ready to be accessed.

ACR_ImagePushed

That’s a good prerequisite if you’d like to use the Container Image for a Kubernetes Service or a Container Instance within Azure, as it can be now easily refered and accessed.

Conclusion

The Azure Container Registry is a great tool, which can be easily created within the Azure Portal for (among others) storing and managing Container Images. If you’re using additional services within the Azure Portal, like the Azure Kubernetes Service or Azure Container Instances, then I would recommend to use the Azure Container Registry, because of following observations which I made during some implementations:

Refering to Images from an Azure Container Registry within the Azure Portal:

ACR_Benefit_ACI

Refering to Images from a private Registry within the Azure Portal:

ACR_Benefit_ACI_privateRegistry

The same is true according to the deployments of Workloads in an Azure Kubernetes Service: you won’t need to provide the credentials e.g.: within your YAML file.

Please consider that this information is supplied without guarantee, I’ve just decribe which observations I made during the implementations.

Microsoft: Container Registry

Microsoft: Docs - Container Registry get started with Docker CLI

Dockerfile of the Example Container