Lab 009: Working with Azure Container Registry
Requirements
The Nautilus DevOps team has been tasked with setting up a containerized application. They need to create a Azure Container Registry (ACR) to store their Docker images. Once the repository is created, they will build a Docker image from a Dockerfile located on the azure-client host and push this image to the ACR repository. This process is essential for maintaining and deploying containerized applications in a streamlined manner.
-
Create a ACR repository named devopsacr26050 under East US.
-
Pricing plan must be Basic.
-
Dockerfile already exists under /root/pyapp directory on azure-client host.
-
Build a Docker image using this Dockerfile and push the same to the newly created ACR repo. The image tag must be latest i.e devopsacr26050:latest.
The solution can be implemented using both the Azure Cloud Console and the Azure CLI. This document outlines the CLI-based approach to accomplish these tasks. It is recommended to first explore the Azure Cloud Console for hands-on experience and a practical understanding of the process before utilizing the CLI approach, unless specifically instructed otherwise.
Prerequisites
- Azure CLI and Docker are installed on the host.
- You are authenticated with Azure CLI.
- Dockerfile exists at
/root/pyapp.
Steps
ACR_NAME="devopsacr26050"
RESOURCE_GROUP=$(az group list --query "[?contains(name, 'kml')].name | [0]" --output tsv)
LOCATION="eastus"
SKU="Basic"
DOCKERFILE_PATH="/root/pyapp"
IMAGE_TAG="$ACR_NAME.azurecr.io/$ACR_NAME:latest"
az acr create \
--resource-group "$RESOURCE_GROUP" \
--name "$ACR_NAME" \
--sku "$SKU" \
--location "$LOCATION"
az acr login --name "$ACR_NAME"
docker build -t "$IMAGE_TAG" "$DOCKERFILE_PATH"
docker push "$IMAGE_TAG"
Verification
- Confirm ACR
devopsacr26050exists with SKUBasic. - Confirm image
devopsacr26050:latestis present in ACR.
az acr show --resource-group "$RESOURCE_GROUP" --name "$ACR_NAME" --query "{name:name,sku:sku.name,location:location}" --output table
az acr repository list --name "$ACR_NAME" --output table
az acr repository show-tags --name "$ACR_NAME" --repository "$ACR_NAME" --output table