liveBook · Manning

Azure CLI

As explained in Learn Docker in a Month of Lunches, Second Edition

Azure CLI is Microsoft's command-line tool for creating and managing Azure resources and services.

Azure CLI is a command-line way to create and manage Azure resources. For a quick container test, it can take you from an Azure login to a running Azure Container Instance (ACI), then show its logs. Add --help to an az container command when you need its options. section 14.1

# log in to your Azure subscription:
az login
# create a Resource Group - a logical group for Azure services:
az group create --location eastus --name diamol-ch14
# create a container instance to run a simple Hello World app:
az container create -g diamol-ch14 --name hello `
 --image ghcr.io/diamol2e/ch14-hello-cloud `
 --os-type Linux --cpu 0.1 --memory 0.1
# print the container logs:
az container logs -n hello -g diamol-ch14

Start with an Azure subscription and the CLI installed. This sequence signs in, creates a resource group, runs a small Linux container, and prints its logs. section 14.1

The container create command specifies an image, operating system, CPU, and memory. Azure reserves capacity, pulls the image, and starts the container. To expose a web container, add a port and a unique DNS label, then query its full domain name. CPU sizing affects both application performance and the Azure bill. section 14.1

# choose a good DNS name and put in a variable - with PowerShell:
$DNS_PREFIX='<unique-name>'
# or Linux shell:
DNS_PREFIX='<unique-name>'

# now create the container using the DNS prefix you set:
az container create -g diamol-ch14 --name hello-web `
 --image ghcr.io/diamol2e/ch14-hello-cloud-web `
 --ports 80 --dns-name-label $DNS_PREFIX `
 --os-type Linux --cpu 0.5 --memory 0.5
# query ACI to print the full domain name which routes to the container:
az container show -g diamol-ch14 -n hello-web --query 'ipAddress.fqdn'

Use the PowerShell or Linux-shell variable form that matches your terminal; create a web container and query the address to open in a browser. section 14.1

The same CLI manages Azure Container Registry (ACR). Create a registry with a globally unique name, then use az acr login to configure Docker CLI authentication. That login uses a time-limited token: if authentication fails later, log in again. CLI commands can import an image, build one from a local source folder, and list repository tags; Docker commands can inspect and pull the resulting image. section 14.2

cd ch14/exercises/hello-cloud-web
# build locally:
docker build -t diamol/ch14-web --quiet .
# and build the same image in ACR:
az acr build --image diamol/ch14-web --registry ${ACR_NAME} .
# you may get a TasksOperationsNotAllowed error if you're using
# free credits - if you do just import the image instead:
az acr import -n $ACR_NAME --source `
ghcr.io/diamol2e/ch14-hello-cloud-web -t diamol/ch14-web
# print the tag list for the new image repository:
az acr repository show-tags -n ${ACR_NAME} --repository diamol/ch14-web

Compare a local Docker build with an ACR build. If free credits produce a TasksOperationsNotAllowed error, use the shown image-import alternative, then check the tags. section 14.2

For a private image, ACI needs registry credentials; the CLI can create a repository-scoped ACR token and pass its credentials when creating the container. Separate nonproduction and production registries can also be secured independently. When the exercise is finished, delete the resource group with az group delete --name diamol-ch14 --yes. section 14.2 section 14.2

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Walks through runnable commands, verification, and an authentication-error caveat; does not explain CLI internals.
Examples
Uses a Hello World container, a publicly addressed web container, and local-versus-ACR image builds.
What it assumes
Requires an Azure subscription and installed Azure CLI; introduces the needed az commands through examples.
What you can do after
Operate/configure it to run ACI containers, inspect logs, and create and use an ACR registry.
How it connects
Connects Azure Container Instances, Azure Container Registry, resource groups, Docker CLI, DNS, and CI/CD.

Also explained in

Compare how 4 books explain Azure CLI →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.