Overview and What You Will Learn
Azure Container Instances (ACI) runs a container in seconds with no cluster to manage, while Azure Kubernetes Service (AKS) orchestrates many containers with scaling, service discovery, and self-healing. Choose ACI when you need to run one container or a short task, and choose AKS when many interdependent services need coordination. This lab runs a web container and a one-off job on ACI so you can feel the low overhead, then shows exactly what ACI leaves for you to build yourself.
By the end you will be able to:
- Deploy a public container on ACI and read its state, logs, and address
- Run a run-to-completion job with a restart policy
- Describe a multi-container group and how it differs from a Kubernetes pod
- Decide between ACI, Azure Container Apps, and AKS with a simple framework
Why This Matters in Production
Picking the wrong platform is expensive in both directions. A small team that creates an AKS cluster to run one daily data-processing container inherits cluster upgrades, node patching, and Kubernetes version management for a workload that never needed them. A team that stretches ACI across a dozen services ends up hand-building load balancing, service discovery, and rollouts that Kubernetes already provides.
A team at a company like Shopify might use ACI for an occasional report job, and AKS for the cart, checkout, and inventory services that must scale and recover on their own. The same container image runs on either, so the choice is about operations, not about the code.
Core Principles
The deciding question is not "do I have containers" but "do I have several interdependent services that need coordinated scaling, discovery, and recovery". If the honest answer is no, ACI or Azure Container Apps is usually the lower-overhead choice.
services?"}:::tool Q1 -->|no| Q2{"Short task or
simple service?"}:::tool Q2 -->|yes| ACI["Azure Container
Instances"]:::cloud Q2 -->|needs scaling| ACA["Azure Container
Apps"]:::app Q1 -->|yes| Q3{"Need Kubernetes
APIs or control?"}:::tool Q3 -->|yes| AKS["AKS"]:::bad Q3 -->|no| ACA classDef tool fill:#326CE5,color:#FFFFFF classDef cloud fill:#D1FAE5,color:#1E293B classDef app fill:#EDE9FE,color:#1E293B classDef bad fill:#FFEDD5,color:#1E293B
The two services differ on almost every operational axis:
| Factor | ACI | AKS |
|---|---|---|
| Setup | One command, ready in about a minute | Cluster and node pools to design and create |
| Scaling | Manual, no built-in autoscale | Pod and node autoscaling |
| Networking | Public IP or VNet, no built-in ingress | Services, ingress, network policies |
| Recovery | Restart policy only | Rescheduling, probes, rolling updates |
| Upkeep | Almost none | Version and node upgrades forever |
Azure Container Apps sits in the middle. It is a serverless platform built on Kubernetes that gives you autoscaling, revisions, and ingress without exposing the cluster, so it is often the right answer for a handful of HTTP services or event-driven jobs.
Detailed Step-by-Step Practical Lab
Step 1: Create a resource group.
RG=rg-aci-lab-mumbaiaz group create --name $RG --location centralindiaStep 2: Deploy a web container. The DNS label gives the container a stable name, because the IP address can change if the container group is recreated. Labels must be unique per region, so a random suffix is added.
DNS=aci-hello-rahul-$RANDOM az container create \ --resource-group $RG \ --name hello-web \ --image mcr.microsoft.com/azuredocs/aci-helloworld \ --os-type Linux \ --cpu 1 \ --memory 1.5 \ --ports 80 \ --ip-address Public \ --dns-name-label $DNSStep 3: Check its state and call it. Notice there is no cluster, node pool, or Kubernetes version anywhere in the process.
az container show --resource-group $RG --name hello-web \ --query "{state:instanceView.state, fqdn:ipAddress.fqdn, ip:ipAddress.ip}" \ --output table curl -s http://$DNS.centralindia.azurecontainer.io | head -n 5Step 4: Read the logs and events. Logs come straight from the Azure CLI, with no kubectl involved.
az container logs --resource-group $RG --name hello-webaz container show --resource-group $RG --name hello-web \ --query "containers[0].instanceView.events"Step 5: Run a one-off job. A restart policy of OnFailure makes the container run once, retry only if it fails, and stop. Billing stops when it stops, which is ideal for short tasks.
az container create \ --resource-group $RG \ --name wordcount-job \ --image mcr.microsoft.com/azuredocs/aci-wordcount:latest \ --restart-policy OnFailure \ --environment-variables NumWords=5 MinLength=6 \ --cpu 1 \ --memory 1 az container show --resource-group $RG --name wordcount-job \ --query instanceView.state --output tsvaz container logs --resource-group $RG --name wordcount-jobStep 6: Describe a multi-container group. A container group is ACI's version of a pod: containers share a network namespace and lifecycle. Save this as container-group.yaml.
apiVersion: '2021-10-01'location: centralindianame: web-with-sidecartype: Microsoft.ContainerInstance/containerGroupsproperties: osType: Linux containers: - name: web properties: image: mcr.microsoft.com/azuredocs/aci-helloworld ports: - port: 80 resources: requests: cpu: 1.0 memoryInGB: 1.5 - name: sidecar properties: image: mcr.microsoft.com/azuredocs/aci-tutorial-sidecar resources: requests: cpu: 1.0 memoryInGB: 1.5 ipAddress: type: Public ports: - protocol: tcp port: 80az container create --resource-group $RG --file container-group.yamlaz container show --resource-group $RG --name web-with-sidecar \ --query "containers[].name" --output tsvStep 7: Count what ACI does not do for you. Imagine the same team now needs five services that call each other by name, scale independently, and recover automatically. On ACI each of these becomes your own work:
- Autoscaling: nothing adds or removes instances for you
- Service discovery: services have no internal names, only IPs and DNS labels
- Rolling updates: replacing a version means deleting and recreating the group
- Ingress and TLS: you add Application Gateway or Front Door yourself
- Health-based recovery: only the restart policy exists, with no readiness gating
Those gaps are exactly what AKS and Container Apps fill.
Step 8: Clean up.
az group delete --name $RG --yes --no-waitProduction Best Practices & Common Pitfalls
- Match the platform to the workload shape: ACI suits tasks, burst jobs, and simple services. AKS suits platforms of many services. Container Apps suits a few HTTP or event-driven services that need autoscaling.
- Schedule jobs outside ACI: ACI has no built-in scheduler, so trigger runs from Logic Apps, Azure Functions timers, Data Factory, or a pipeline.
- Pull images with a managed identity: Assign the container group an identity with the
AcrPullrole on your registry instead of embedding registry credentials. - Use secure environment variables for secrets: Values set with
--secure-environment-variablesare not shown in the container group's properties. For stronger handling, read from Azure Key Vault. - Deploy into a virtual network for private workloads: Do not expose internal jobs on public IPs.
- Mind the billing model: ACI bills per second for the vCPU and memory you allocate while the group runs. A container that runs all day, every day, usually costs more than the same workload on a VM or in Container Apps.
- Remember AKS has ongoing costs: Upgrades, node patching, and version compatibility need attention long after the first deployment.
Common MistakeDeploying a full AKS cluster for a single simple container "to match our other workloads". Consistency is rarely a functional requirement, and the added cluster management delivers no benefit for a workload this small.
Common MistakeRunning an always-on production service on ACI and expecting self-healing and scaling. A restart policy only restarts the container, and nothing adds capacity under load.
TipThe two are not exclusive. AKS virtual nodes use ACI behind the scenes to burst extra pods beyond the cluster's own nodes, without waiting for new VMs to be provisioned.
RememberContainers are portable. An image that runs on ACI runs unchanged on Container Apps or AKS, so you can start simple and move up when the workload demands it.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
az container create |
Deploy a container group on ACI |
az container show |
Check state, IP address, and events |
az container logs |
Read container output |
az container exec |
Open a shell inside a running container |
az container restart |
Restart a container group |
az container delete |
Remove a group and stop billing |
az containerapp create |
Create a Container Apps app, for comparison |
az aks create |
Create an AKS cluster, for comparison |
| Symptom | Likely cause |
|---|---|
| Group stuck in Waiting | Image pull failed, so check the image name and registry access |
| Container restarts repeatedly | The app exits on start, so check logs and the restart policy |
| DNS label rejected | The label is already used in that region |
| Cannot reach the container | Missing --ports or a firewall or NSG blocking the port |