Post

Create an Azure Container Registry

In this tutorial, we will create a private managed container image registry using Azure Container Registry (ACR) in three different ways.

  1. Via the Azure Portal
  2. Via the Azure command line interface
  3. Via a Terraform template.

After creating the registry, we will then pull the hello-world container image from DockerHub locally, apply a tag to the image and then push the container image into our Azure Container Registry.

This content is available in video form on the Cloud Engineer Skills YouTube channel.

Creating an Azure Container Registry via the Azure Portal

Prerequisites

Before we get started for this tutorial you will need the following:

Azure Portal Instructions

  • Login in your Microsoft Azure account via the Azure Portal
  • Select All Services
  • Filter All Services by container
  • Select Azure Container Registry
  • Select the Create button
  • Enter the following details and select Create
    • Resource Group: cloudengineerskills-acr-rg
    • Azure Container Registry Name: cloudengineerskillsacr
  • Wait for the resource to be created
  • Go the Azure Container Registry resource that has been created
  • Under Services select Repositories and you should no repositories
  • Make sure Docker is running
  • This is the docker image will be retrieving locally which we will then push into our Azure Container Registry
1
2
3
4
5
6
az login
docker pull hello-world
docker tag hello-world cloudengineerskillsacr.azurecr.io/hello-world:v1
az acr login --name cloudengineerskillsacr
docker push cloudengineerskillsacr.azurecr.io/hello-world:v1
az acr run --registry cloudengineerskillsacr --cmd 'cloudengineerskillsacr.azurecr.io/hello-world:v1' /dev/null

Creating an Azure Container Registry via the Azure CLI

Prerequisites

Before we get started for this tutorial you will need the following:

Azure CLI Instructions

1
2
3
4
5
6
7
8
9
10
11
az login
az group create --name cloudengineerskills-acr-cli-rg --location eastus
az acr create --resource-group cloudengineerskills-acr-cli-rg --name cloudengineerskillscliacr --sku Premium
az acr repository list --name cloudengineerskillscliacr --output table
docker pull hello-world
docker tag hello-world cloudengineerskillscliacr.azurecr.io/hello-world:v1
az acr login --name cloudengineerskillscliacr
docker push cloudengineerskillscliacr.azurecr.io/hello-world:v1
az acr repository list --name cloudengineerskillscliacr --output table
az acr run --registry cloudengineerskillscliacr --cmd 'cloudengineerskillscliacr.azurecr.io/hello-world:v1' /dev/null
az group delete --resource-group cloudengineerskills-acr-cli-rg

Creating an Azure Container Registry via Terraform

Prerequisites

Before we get started for this tutorial you will need the following:

Terraform Instructions

  • Create a main.tf file
    • https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry
    • https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# We strongly recommend using the required_providers block to set the
# Azure Provider source and version being used
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.110.0"
    }
  }
}

# Configure the Microsoft Azure Provider
provider "azurerm" {
#   skip_provider_registration = true # This is only required when the User, Service Principal, or Identity running Terraform lacks the permissions to register Azure Resource Providers.
  features {}
}

# Create a resource group
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group#arguments-reference
resource "azurerm_resource_group" "rg" {
  name     = "cloudengineerskills-acr-tf-rg"
  location = "West US 2"
  tags = {
    environment = "dev"
    source = "terraform"
    owner = "cloudengineerskills"
  }
}

# Create a container registry
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_registry#argument-reference
resource "azurerm_container_registry" "acr" {
  name                = "cloudengineerskillstfacr"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
  sku                 = "Premium"
  admin_enabled       = true
  tags = {
    environment = "dev"
    source = "terraform"
    owner = "cloudengineerskills"
  }
}
1
2
3
4
5
6
7
8
9
10
11
terraform init
az login
terraform apply
az acr repository list --name cloudengineerskillstfacr --output table
docker pull hello-world
docker tag hello-world cloudengineerskillstfacr.azurecr.io/hello-world:v1
az acr login --name cloudengineerskillstfacr
docker push cloudengineerskillstfacr.azurecr.io/hello-world:v1
az acr repository list --name cloudengineerskillstfacr --output table
az acr run --registry cloudengineerskillstfacr --cmd 'cloudengineerskillstfacr.azurecr.io/hello-world:v1' /dev/null
terraform destroy
This post is licensed under CC BY 4.0 by the author.