liveBook · Manning

Azure Container Instances

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

Azure Container Instances is a Microsoft Azure service for running containers without managing virtual machines or an orchestration cluster.

Need a test environment without setting up virtual machines or a container cluster? Azure Container Instances (ACI) runs a container image on Azure-managed compute. It is a practical option for simple applications with modest scaling needs, especially short-lived smoke-test environments in a CI/CD workflow. Applications needing the features of a full container platform may need a different service. section 14.0 section 14.1

To get started, sign in with the Azure CLI, create a resource group, then use `az container create` to run an image. Specify its operating system, CPU, and memory. ACI reserves capacity, pulls the image, and starts the container; `az container logs` lets you check its output. The Azure Portal also shows lifecycle events and logs. 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

Follow this first run from Azure login through resource-group creation, container creation, and log inspection. section 14.1

For a web application, publish port 80 and choose a unique DNS name label. Query the instance for its full domain name, then open it in a browser. This turns a running container into a reachable test environment. 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 web-container commands to publish a port and retrieve the assigned domain name. section 14.1

Choose compute size deliberately: running the same application with different CPU allocations changes its performance and its Azure cost. For a private image in Azure Container Registry (ACR), create a registry token with read permissions and provide its credentials when creating the instance. An ACR image can be built in Azure or imported; an ACR build task may be unavailable with free credits. When finished experimenting, delete the resource group to remove its resources. section 14.1 section 14.2

# generate an ACR token and print the password:
az acr token create -n aci-reader -r $ACR_NAME `
 --repository diamol/ch14-web content/read metadata/read `
 --query 'credentials.passwords[0].value'
# think of a new unique DNS prefix and store it - in PowerShell:
$DNS_PREFIX='<new-name>'
# OR Linux shell:
DNS_PREFIX='<new-name>'
# and run an ACI image - the username is your ACR token name
# and you will need to insert your token password:
az container create -g diamol-ch14 --name web-2 `
 --image "${ACR_NAME}.azurecr.io/diamol/ch14-web" `
 --ports 80 --dns-name-label ${DNS_PREFIX} `
 --os-type Linux --cpu 0.2 --memory 0.2 `
 --registry-login-server "${ACR_NAME}.azurecr.io" `
 --registry-username aci-reader --registry-password '<token-password>'
# print the full domain:
az container show -g diamol-ch14 --name web-2 --query 'ipAddress.fqdn'
# now you can browse to the website

See the registry login options and read-only token credentials needed to run a private ACR image in ACI. section 14.2

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

How deep it goes
Walks through creation, logs, public DNS, compute sizing, and private-image deployment; does not descend into Azure’s underlying infrastructure.
Examples
Runs a Hello World container, publishes a web container, compares CPU allocations, and deploys an image from a private registry.
What it assumes
Assumes familiarity with container images and requires an Azure subscription and Azure CLI; starts the ACI procedure with login.
What you can do after
Operate/configure it with the Azure CLI to start containers, inspect logs, expose a web application, and use a private image.
How it connects
Connects ACI to managed container services, CI/CD, Azure Container Registry, container images, and resource groups.

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.