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
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:
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.
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.
Pushing an Image to the Container Registry
Storing your Container Image to the Container Registry can be done with following steps:
- Login to the Container Registry
- Tag your Image so that it fits for the Container Registry
- 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:
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:
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.
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:
- More comfortable way of accessing the Container Images: You won’t need to provide the credentials of the Container Registry (in contrast to a private Registry) as the available Container Images are already listed within the e.g.: Container Instances service (for example see the pictures below).
Refering to Images from an Azure Container Registry within the Azure Portal:
Refering to Images from a private Registry within the Azure Portal:
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.
- Faster Provisioning: I’ve observed for several deployments, that pulling Images from the Azure Container Registry seems to be faster than e.g.: pulling it from your private Registry.
Please consider that this information is supplied without guarantee, I’ve just decribe which observations I made during the implementations.
Links
Microsoft: Docs - Container Registry get started with Docker CLI