You are currently viewing Azure Kubernetes Service and Container Registry

Azure Kubernetes Service and Container Registry

In this article, let’s have a look at how can you create a container registry on Azure and how can you use it.

If you do not have an Azure account,  you can create free account on Azure. Because you will need Azure access for following some of the steps.

Azure Container Registry

If you are using docker, you should be aware of docker hub. It is a public repository. As long as you have account on the docker hub, you should be able to download and use any image from that registry.

What if you want to have a private container registry for your application or organization ?

You can obviously set it up yourself on your server. But when you decide to setup on your own servers, you have to think about many things like storage, access management and security, usage of tools, etc.

Microsoft Azure provides you a simpler way to have a private registry to hose the container images. ACR easily integrates with Docker Swarm, Kubernetes, etc. You can also use the same docker tooling with ACR.

And you can manage the access to the registry using Azure Active Directory. A user or service can access registry only if AAD allows it. How cool is that !

Let’s Create Private Registry

Let’s start by creating an ACR instance using Azure Portal. Click on “Create a resource” button from the left navigation bar and select container registry and click on create.

It will bring below dialog. You need to provide:

  • Registry name, this should be globally unique
  • Subscription, under which this is being created
  • Resource group, under which resource (ACR) should be placed
  • Location, the geographical location where ACR is physically located
  • Admin user, keep this disabled for now
  • SKU, pricing tier (Basic, Standard or Premium). You can select any one, they will decide the storage space allocated and the pricing.

Once you click on “Create” button, the Azure will start deployment and it should be finished in next couple of seconds.

Now if you have docker installed on your local machine or laptop, you can start using this registry.

Using from your laptop

If you have docker on your machine, you can run below command. This will download the hello world image from docker hub on your machine and will run it.

docker run -it hello-world

Use docker login command to login to the Azure container registry you created. Please note that mysamples is the name we provided while creating container registry.

docker login mysamples.azurecr.io

Then prefix the image with your Azure container registry login URI so that it can be pushed to you repository. Then run docker push command to push the image to your ACR.

docker tag hello-world mysamples.azurecr.io/hello-world
docker push mysamples.azurecr.io/hello-world

Now your private registry contains a docker image. You can pull image from your registry and run it using below command.

docker pull mysamples.azurecr.io/hello-world

The above command demonstrates how you can use private registry from your laptop. Instead of downloading image from docker hub, you can create image of your application and push it to your repository.

ACR Create: Using Command Line !

You can also use Azure command line interface to create the azure container registry. Below are some of the commands which can be helpful for that purpose:

# creates the resource group with name Samples in WestEurope 
az group create --name Samples --location westeurope

# creates ACR instance with name mySamples, pricing tier Standard
az acr create --resource-group Samples   \
              --name mySamples           \
              --sku Standard             

# To perform any operation you need to login to ACR
az acr login --name mySamples

# To show the list of images available on ACR
az acr repository list --name mySamples --output table

# To see all tags of image with name ImageName
az acr repository show-tags --name mySamples   \
              --repository imageName           \
              --output table

I hope this article has provided you enough information to setup your private repository. Please comment and let me know your thoughts.

Leave a ReplyCancel reply