Getting started with Azure Container Registry

In this post, I'll walk you through creating an Azure Container Registry and push an image into it.

Pre-requisites

If following along at home, you will need:

I'll be using one of my images from Docker hub, so I'll grab that before we start:


docker run -d --name website1 -p 8091:80 redfolder/the-worlds-best-website

Which will output something like:


Unable to find image 'redfolder/the-worlds-best-website:latest' locally
latest: Pulling from redfolder/the-worlds-best-website
8176e34d5d92: Pull complete
5b19c1bdd74b: Pull complete
4e9f6296fa34: Pull complete
73190e582fec: Pull complete
Digest: sha256:6bf6eef4b0094c6c59e06b0b6aa7964fdc21acc77f733d2308c0beb943b66f51
Status: Downloaded newer image for redfolder/the-worlds-best-website:latest
fe7bc8b942966f6135459481402ea619eacd63c2f1072291f1885d3c5f102e42

This will give, as the name suggests, the worlds best website on http://localhost:8091: website 1 screenshot

Ok, so let's start ...

Create the Container Registry

I'll create a resource group (makes it nice and easy to clean up later):


az group create --name "ContainerPlayground" --location "northeurope"

Which gives the output:


{
  "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/ContainerPlayground",
  "location": "northeurope",
  "managedBy": null,
  "name": "ContainerPlayground",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null
}

I then create the Azure Container Registry. The Basic SKU is more than enough for me to play with and I want to call it "redfolder":


az acr create --name "redfolder" --resource-group "ContainerPlayground" --location "northeurope" --admin-enabled true --sku Basic

Which gives:


{
  "adminUserEnabled": true,
  "creationDate": "2019-01-24T11:30:58.698040+00:00",
  "id": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/ContainerPlayground/providers/Microsoft.ContainerRegistry/registries/redfolder",
  "location": "northeurope",
  "loginServer": "redfolder.azurecr.io",
  "name": "redfolder",
  "networkRuleSet": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "ContainerPlayground",
  "sku": {
    "name": "Basic",
    "tier": "Basic"
  },
  "status": null,
  "storageAccount": null,
  "tags": {},
  "type": "Microsoft.ContainerRegistry/registries"
}

And that's it. You've created the Azure Container Registry. Its available to me as redfolder.azurecr.io (see the loginServer property).

Authenticate Docker to new Container Registry

Before we can do anything useful with the Registry, you need to authenticate.

So firstly I'll get my login credentials:


az acr credential show --name redfolder

Which gives:


{
  "passwords": [
    {
      "name": "password",
      "value": "9MT56hWrpRlFFMF184DXhA/DptdOVkyq"
    },
    {
      "name": "password2",
      "value": "3IE0ur6Ijnfwz9BQ/RbKEdekR8/XBtn0"
    }
  ],
  "username": "redfolder"
}

I'll then use them to log Docker into redfolder.azurecr.io:


docker login redfolder.azurecr.io

Ok, we now have Docker authenticated to the my new Azure Container Registry.

Push an image to the new Container Registry

Now I want to push an image to it. First, let's just take a look at what images I have locally:


docker images

Which gives:


REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
redfolder/the-worlds-best-website   latest              3905ac481922        11 months ago       109MB

I'll take that image, and tag it ready for pushing to the Azure Container Registry:


docker image tag redfolder/the-worlds-best-website:latest redfolder.azurecr.io/the-worlds-best-website:latest

Let's just check that the Azure Container Registry version is in the images:


docker images

Which gives:


REPOSITORY                                     TAG                 IMAGE ID            CREATED             SIZE
redfolder/the-worlds-best-website              latest              3905ac481922        11 months ago       109MB
redfolder.azurecr.io/the-worlds-best-website   latest              3905ac481922        11 months ago       109MB

So far this has all been local. Time to push that image to the Azure Container Registry:


docker push redfolder.azurecr.io/the-worlds-best-website:latest

Which gives:


The push refers to repository [redfolder.azurecr.io/the-worlds-best-website]
aadb9ea35a48: Pushed
e89b70d28795: Pushed
832a3ae4ac84: Pushed
014cf8bfcb2d: Pushed
latest: digest: sha256:6bf6eef4b0094c6c59e06b0b6aa7964fdc21acc77f733d2308c0beb943b66f51 size: 1156

All done. Next task it to test it works.

Creating an container from the new Container Registry

I'll delete the local copy of the Azure Container Registry version of the image:


docker image rm redfolder.azurecr.io/the-worlds-best-website

Which gives:


Untagged: redfolder.azurecr.io/the-worlds-best-website:latest
Untagged: redfolder.azurecr.io/the-worlds-best-website@sha256:6bf6eef4b0094c6c59e06b0b6aa7964fdc21acc77f733d2308c0beb943b66f51

Double check that locally I don't have that image:


docker images

Which gives:


REPOSITORY                          TAG                 IMAGE ID            CREATED             SIZE
redfolder/the-worlds-best-website   latest              3905ac481922        11 months ago       109MB

And now let's spin up our second website using the Azure Container Registry:


docker run -d --name website2 -p 8092:80 redfolder.azurecr.io/the-worlds-best-website

Which gives:


Unable to find image 'redfolder.azurecr.io/the-worlds-best-website:latest' locally
latest: Pulling from the-worlds-best-website
Digest: sha256:6bf6eef4b0094c6c59e06b0b6aa7964fdc21acc77f733d2308c0beb943b66f51
Status: Downloaded newer image for redfolder.azurecr.io/the-worlds-best-website:latest
db6d786ece85d68b249ce926800aeb92825b1cf075e5236dcce8921094f13cf1

And we should be able to see it working on http://localhost:8092 website 2 screenshot

... and clean up

And should you want to clean up your Azure account, it's a single command to remove everything from Azure:


az group delete --name ContainerPlayground

I hope that helps. Any questions, please feel free to reach out to me.

About the author:

Mark Taylor is an experience IT Consultant passionate about helping his clients get better ROI from their Software Development.

He has over 20 years Software Development experience - over 15 of those leading teams. He has experience in a wide variety of technologies and holds certification in Microsoft Development and Scrum.

He operates through Red Folder Consultancy Ltd.