OnCallReadyStart learning

Azure Lesson 33.14 · Azure V: Compute, App Hosting & the AZ-104 exam · 25 min read

Containers without a cluster: ACR, Container Instances, Container Apps

In plain words

Your app is packed in a container image, like a meal in a lunchbox. Azure Container Registry is the fridge where the lunchboxes are kept. Container Instances is a microwave: put one lunchbox in, it runs, you pay per second, nothing else. Container Apps is a canteen: it serves as many lunchboxes as there are hungry people, closes the counter when nobody comes, and can serve the new recipe to a few people first.

None of them makes you run a Kubernetes cluster yourself.

Containers on Azure without a cluster: ACR, Container Instances, Container Apps

Azure II ran containers on AKS: a Kubernetes cluster you upgrade, scale and pay for around the clock. Plenty of workloads do not need one. A nightly report job, a webhook receiver, an internal API with three users - for those Azure has two serverless options, Azure Container Instances (ACI) and Azure Container Apps, and both pull their images from the same place AKS does, an Azure Container Registry (ACR). This lesson builds an image in ACR without Docker on your machine, runs it on ACI, then on Container Apps with revisions, a traffic split and scale rules.

Need to know: ACR comes in Basic, Standard and Premium (Premium adds geo-replication, private endpoints, zone redundancy); pulls are authorised with Microsoft Entra (the AcrPull role) - the admin user is a shared password for emergencies. az acr build builds in Azure (ACR Tasks), az acr import copies an image in. ACI runs a container group (one or more containers on one host, sized in vCPU and GB, with a restart policy Always / OnFailure / Never) - no scaling, no load balancing. Container Apps runs apps in an environment, with ingress, immutable revisions (single or multiple active), traffic splitting, and scale rules (HTTP concurrency, TCP, CPU/memory, queues - KEDA under the hood) between min and max replicas, down to zero.

The registry

$ cd ~/oncall-lab/labs/4b-azure/az5/containers
$ cat app/Dockerfile
FROM nginx:1.27-alpine
COPY index.html /usr/share/nginx/html/
$ az acr create -g rg-az5-apps -n acrreports5 --sku Basic --query "{server:loginServer, sku:sku.name, admin:adminUserEnabled}" -o json
{
  "admin": false,
  "server": "acrreports5.azurecr.io",
  "sku": "Basic"
}

The registry name is global (acrreports5.azurecr.io), 5-50 alphanumerics, no dashes. The SKUs differ in included storage, throughput and a few features:

BasicStandardPremium
usedev, small teamsmost productionmany regions, private networks
geo-replication--yes
private endpoints, firewall rules--yes
zone redundancy--yes
content trust, customer-managed keys--yes

You can change SKU later (az acr update --sku Premium) without losing images.

Build without Docker. az acr build uploads the build context (here the app folder) and runs the docker build in Azure (an ACR Task), then pushes the result:

$ az acr build -r acrreports5 -t reports:v1 app 2>/dev/null | tail -4
    tag: 1.27-alpine
  git: {}

Run ID: c1 was successful after 25s
$ az acr repository list -n acrreports5 -o tsv
reports
$ az acr repository show-tags -n acrreports5 --repository reports -o tsv
v1

az acr import --source docker.io/library/nginx:1.27 --image nginx:1.27 copies an image from another registry without pulling it through your machine - the way to stop depending on Docker Hub's rate limits in production. ACR Tasks can also rebuild on a git push or when a base image is updated.

Who may pull. Three ways, best first:

  1. Microsoft Entra identities with a role: AcrPull (pull), AcrPush (push and pull), on the registry. Your own az acr login uses your account; AKS, ACI, Container Apps and App Service use a managed identity with AcrPull.
  2. Repository-scoped tokens for a CI system outside Azure.
  3. The admin user (az acr update --admin-enabled true): one shared username and two passwords with push and pull on everything. Off by default; policy usually keeps it off.

Azure Container Instances: one container group, now

$ az container create -g rg-az5-apps -n aci-reports --image acrreports5.azurecr.io/reports:v1 --cpu 1 --memory 1.5 --ports 80 --ip-address Public --dns-name-label reports-az5-01 --os-type Linux
ERROR: (InaccessibleImage) The image 'acrreports5.azurecr.io/reports:v1' in container group 'aci-reports' is not accessible. Please check the image and registry credential.
Code: InaccessibleImage
Message: The image 'acrreports5.azurecr.io/reports:v1' in container group 'aci-reports' is not accessible. Please check the image and registry credential.

A private registry and no credentials: InaccessibleImage. The fix is an identity that may pull

  • a user-assigned managed identity with AcrPull on the registry, named twice: as the group's

identity and as the one to pull with:

$ az identity create -g rg-az5-apps -n id-reports -o none
$ az role assignment create --assignee $(az identity show -g rg-az5-apps -n id-reports --query principalId -o tsv) --role AcrPull --scope $(az acr show -n acrreports5 --query id -o tsv) -o none
$ ID=$(az identity show -g rg-az5-apps -n id-reports --query id -o tsv)
$ az container create -g rg-az5-apps -n aci-reports --image acrreports5.azurecr.io/reports:v1 --cpu 1 --memory 1.5 --ports 80 --ip-address Public --dns-name-label reports-az5-01 --os-type Linux --assign-identity $ID --acr-identity $ID --query "{state:instanceView.state, fqdn:ipAddress.fqdn, restart:restartPolicy}" -o json
{
  "fqdn": "reports-az5-01.westeurope.azurecontainer.io",
  "restart": "Always",
  "state": "Running"
}
$ curl -s http://reports-az5-01.westeurope.azurecontainer.io/
<h1>reports v1</h1>
$ az container logs -g rg-az5-apps -n aci-reports
/docker-entrypoint.sh: Configuration complete; ready for start up
198.51.100.24 - - [Tue, 22 Sep 2026 20:00:30 GMT] "GET / HTTP/1.1" 200 - "-" "curl/8.14.1"

What to know about ACI:

  • Sizing is per container (--cpu, --memory in GB) and the group gets the sum; there is a per-group maximum per region (here 4 vCPU and 16 GB for Linux), and you pay per second for what you requested, from start to stop.
  • Restart policy: Always (the default - a web server), OnFailure (a job that should retry on a non-zero exit), Never (run once, keep the exit code for you to read). A batch job with Always is restarted forever after it succeeds.
  • No scaling, no load balancer, no rolling update. One group is one set of containers on one host; for more, you create more groups. Changing the image means recreating the group (same command, same name).
  • A public IP + DNS label, or --vnet/--subnet for a private one (the subnet is delegated to Microsoft.ContainerInstance/containerGroups).

Container Apps: an app platform on top of Kubernetes you never see

A Container Apps environment is the boundary: apps in one environment share a virtual network, a Log Analytics workspace for their logs and a default domain. Apps are created into it:

$ az containerapp env create -g rg-az5-apps -n cae-reports -l westeurope -o none

Container Apps environment created. To deploy a container app, use: az containerapp create --help
$ az containerapp create -g rg-az5-apps -n reports-api --environment cae-reports --image acrreports5.azurecr.io/reports:v1 --registry-server acrreports5.azurecr.io --registry-identity $ID --target-port 80 --ingress external --cpu 0.5 --memory 1.0Gi --min-replicas 1 --max-replicas 5 --scale-rule-name http-load --scale-rule-type http --scale-rule-http-concurrency 30 --query properties.configuration.ingress.fqdn -o tsv

Container app created. Access your app at https://reports-api.calmcloud-05e8ebc0.westeurope.azurecontainerapps.io/

reports-api.calmcloud-05e8ebc0.westeurope.azurecontainerapps.io
$ curl -s https://$(az containerapp show -g rg-az5-apps -n reports-api --query properties.configuration.ingress.fqdn -o tsv)/
<h1>reports v1</h1>

Ingress external gives the app a public HTTPS endpoint with a managed certificate; internal makes it reachable only inside the environment; no ingress at all suits background workers. --target-port is the port the container listens on.

Sizing comes in fixed CPU/memory pairs on the Consumption plan (0.25 vCPU / 0.5 GiB, 0.5 / 1.0, 0.75 / 1.5 ...). Anything else is refused:

$ az containerapp update -g rg-az5-apps -n reports-api --cpu 0.75 --memory 1.0Gi
ERROR: (ContainerAppInvalidResourceTotal) The total requested CPU and memory resources for this application (CPU: 0.75, memory: 1.0Gi) is invalid. Total CPU and memory for all containers defined in a Container App must add up to one of the following CPU - Memory combinations: [cpu: 0.25, memory: 0.5Gi]; [cpu: 0.5, memory: 1.0Gi]; [cpu: 0.75, memory: 1.5Gi]; [cpu: 1.0, memory: 2.0Gi]; [cpu: 1.25, memory: 2.5Gi]; [cpu: 1.5, memory: 3.0Gi]; [cpu: 1.75, memory: 3.5Gi]; [cpu: 2.0, memory: 4.0Gi]
Code: ContainerAppInvalidResourceTotal
Message: The total requested CPU and memory resources for this application (CPU: 0.75, memory: 1.0Gi) is invalid. Total CPU and memory for all containers defined in a Container App must add up to one of the following CPU - Memory combinations: [cpu: 0.25, memory: 0.5Gi]; [cpu: 0.5, memory: 1.0Gi]; [cpu: 0.75, memory: 1.5Gi]; [cpu: 1.0, memory: 2.0Gi]; [cpu: 1.25, memory: 2.5Gi]; [cpu: 1.5, memory: 3.0Gi]; [cpu: 1.75, memory: 3.5Gi]; [cpu: 2.0, memory: 4.0Gi]

Scaling is replicas between --min-replicas and --max-replicas, driven by scale rules:

rule typescales onexample
httpconcurrent HTTP requests per replica30 requests in flight -> one more replica
tcpconcurrent TCP connectionsa gRPC or database proxy
custom (KEDA)CPU, memory, queue length, Kafka lag, cron...1 replica per 100 messages in a Service Bus queue

With --min-replicas 0 an idle app costs nothing - and the first request after a quiet period waits for a replica to start (a cold start, seconds). Keep min 1 for anything a user waits on. With no scale rule, a Consumption app scales on HTTP with a default concurrency of 10.

$ az containerapp show -g rg-az5-apps -n reports-api --query "properties.template.scale" -o json
{
  "maxReplicas": 5,
  "minReplicas": 1,
  "rules": [
    {
      "http": {
        "metadata": {
          "concurrentRequests": "30"
        }
      },
      "name": "http-load"
    }
  ]
}

Revisions and traffic splitting

Every change to the template (image, environment variables, CPU, scale) creates a new immutable revision named <app>--<suffix>. In single revision mode (the default) the new one takes all traffic and the old one is deactivated. In multiple mode several revisions run at once and you choose the split - a canary without any extra tooling:

$ az containerapp revision set-mode -g rg-az5-apps -n reports-api --mode multiple
"Multiple"
$ sed -i 's/v1/v2/' app/index.html && az acr build -r acrreports5 -t reports:v2 app >/dev/null 2>&1
$ az containerapp update -g rg-az5-apps -n reports-api --image acrreports5.azurecr.io/reports:v2 --revision-suffix v2 -o none
$ az containerapp revision list -g rg-az5-apps -n reports-api --query "[].{revision:name, active:properties.active, traffic:properties.trafficWeight}" -o table
Revision              Active  Traffic
--------------------  ------  -------
reports-api--a1928d9  True    0
reports-api--v2       True    100
$ OLD=$(az containerapp revision list -g rg-az5-apps -n reports-api --query "[0].name" -o tsv)
$ az containerapp ingress traffic set -g rg-az5-apps -n reports-api --revision-weight $OLD=80 reports-api--v2=20 -o table
RevisionName          Weight
--------------------  ------
reports-api--a1928d9  80
reports-api--v2       20
$ for i in $(seq 10); do curl -s https://$(az containerapp show -g rg-az5-apps -n reports-api --query properties.configuration.ingress.fqdn -o tsv)/; done | sort | uniq -c
      8 <h1>reports v1</h1>
      2 <h1>reports v2</h1>

Look at the revision list first: the moment v2 was ready it had 100%. The app's traffic rule was still the default, "latest revision: 100" - so in multiple mode, set the weights by revision name before you deploy the canary (or deploy it with --revision-weight pinned), or the "canary" is a full rollout. After the split, two in ten requests see v2. When it looks healthy, move the weights to 100 for v2 and deactivate the old revision; if not, set the old one back to 100 - a rollback in seconds, no redeploy. Weights must add up to 100, and only active revisions can receive traffic.

Choosing

needuse
a container now, for minutes or hours; a batch job; a sidecar-free toolACI
an HTTP API or worker that scales with load (to zero), canaries, no cluster to runContainer Apps
full Kubernetes: custom controllers, daemonsets, node control, a platform for many teamsAKS
a plain web app or API from code (no container)App Service (next lesson)

On the exam (AZ-104 3.3.1-3.3.4): "pull from ACR without storing a password" = a managed identity with AcrPull; "geo-replication / private endpoint for the registry" = Premium; "a job that should not restart after it succeeds" = restart policy OnFailure or Never; "scale to zero" and "split traffic between versions" = Container Apps; "scale the number of ACI instances automatically" = not ACI.

In an interview: "When would you pick Container Apps over AKS?" - "When the team wants to run containers, not operate Kubernetes: HTTP APIs and workers with scale-to-zero, revisions and traffic splits built in, and no node pools to upgrade. AKS when we need the Kubernetes API itself - operators, daemonsets, network policies, a shared platform for many teams."

Why it helps

Not every container needs AKS. AZ-104 asks you to create a registry, run a container group with ACI, and deploy and scale a Container App - and to choose between them.

The parts that break in practice are identity and sizing: an app that cannot pull because nobody gave its identity AcrPull, an admin password stored in a pipeline, a CPU and memory pair that is not allowed, a new revision getting all the traffic before anyone looked at it.

Commands in this lesson

cd cat az curl sed

FAQ

How should an app pull from ACR?

With a managed identity that has the AcrPull role on the registry. The admin user (one shared username and password) is off by default and should stay off; it exists for quick tests. ACR Tasks (az acr build) can build images in Azure without Docker on your machine.

What is a container group in ACI?

One or more containers scheduled together on the same host, sharing a lifecycle, a network (one IP and ports) and volumes - the ACI equivalent of a pod. Restart policy Always, OnFailure or Never makes it suitable for services or one-off jobs.

What makes Container Apps scale to zero?

Scale rules based on KEDA: HTTP concurrency, a queue length, CPU or a custom scaler, with min replicas 0. With no requests, replicas go to zero and nothing bills for compute; the first request starts one again, with a cold start delay.

What is a revision?

An immutable snapshot of a Container App's template (image, settings, scale). A change to the template creates a new revision. In multiple revision mode, you split ingress traffic between revisions by weight or label - a canary without a service mesh.

ACI, Container Apps, App Service or AKS?

ACI for one-off jobs and simple single groups; Container Apps for microservices and workers that scale with events, including to zero; App Service for web apps that want slots, domains and TLS built in; AKS when you need the Kubernetes API itself - operators, DaemonSets, network policies.

In an interview Mid

When would you pick Container Apps over AKS?

When the team wants to run containers, not operate Kubernetes: HTTP APIs and workers with scale to zero, revisions and traffic splits built in, and no node pools to upgrade. AKS when we need the Kubernetes API itself - operators, daemonsets, network policies, a shared platform for many teams. Either way the image comes from ACR, pulled with a managed identity that has AcrPull.

Also asked: How does an Azure Container Instance pull from a private registry without a password? · What is a revision in Azure Container Apps? · How would you run a nightly batch job in a container on Azure?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.