ComputeLesson 5 of 16

Container Instances (ACI)

Azure Container Instances (ACI) is the fastest way to run a Docker container in the cloud — no cluster, no orchestrator, just a container running in seconds.

Simple Explanation

ACI is like renting a single hotel room — fast, no lease, pay only for the night. AKS is like owning an apartment building. Use ACI for short stays.

When to Use ACI

ACI vs AKS vs App Service

FeatureACIAKSApp Service
Startup timeSecondsMinutes (cluster)Seconds
OrchestrationNoneFull KubernetesBuilt-in PaaS
Long-running servicesNot idealYesYes
ScalingManualAuto (HPA/KEDA)Auto
NetworkingBasic + VNetFull CNIVNet integration
Cost modelPer secondNode VMs always runningPer plan tier
Best forShort tasks, burst jobsMicroservices at scaleWeb apps / APIs

Commands

Azure CLI
# Run a container (nginx example)
az container create \
  --resource-group rg-aci \
  --name ci-web \
  --image nginx:latest \
  --ports 80 \
  --dns-name-label my-aci-demo-2024 \
  --os-type Linux \
  --cpu 1 \
  --memory 1.5

# View container status
az container show \
  --resource-group rg-aci \
  --name ci-web \
  --query instanceView.state

# Stream container logs
az container logs --resource-group rg-aci --name ci-web --follow

# Attach to container (interactive shell)
az container exec \
  --resource-group rg-aci \
  --name ci-web \
  --container-name ci-web \
  --exec-command "/bin/bash"

# Run a batch job (restart policy: Never)
az container create \
  --resource-group rg-aci \
  --name ci-batch-job \
  --image myrepo/myprocessor:latest \
  --restart-policy Never \
  --environment-variables "INPUT_FILE=data.csv" "OUTPUT_BUCKET=results"

# Delete container
az container delete --resource-group rg-aci --name ci-web --yes

Hands-on

  1. Create a container group running nginx with a public DNS label.
  2. Browse to http://<dns-label>.<region>.azurecontainer.io.
  3. Stream logs with az container logs --follow.
  4. Create a second container with --restart-policy Never to simulate a batch job.
  5. Delete both containers and compare the per-second cost in your billing overview.

Debugging Scenario

Issue: Container exits immediately after creation.

Interview Questions

Beginner

What is ACI and when would you use it?

Azure Container Instances runs Docker containers on-demand without managing a cluster. Use for short-lived jobs, burst workloads, CI agents, and quick tests.

What does "restart policy: Never" do?

The container runs once and Azure does not restart it on exit. Ideal for batch jobs that should run exactly once.

Scenario-based

Each commit should run 50 integration test containers in parallel, then shut them down.

ACI is ideal here. Trigger az container create for each test container from your CI, use --restart-policy Never, stream logs, check exit code, then delete. Pay only for test duration.

When would you choose AKS over ACI?

When you have long-running, stateful microservices that need service discovery, persistent volumes, complex networking, Horizontal Pod Autoscaling, and rolling updates.

Summary

ACI is the simplest container runtime in Azure — ideal for short-lived tasks, batch processing, and proof-of-concept work. It starts in seconds and bills by the second. For persistent services, microservices architectures, or anything needing orchestration, use AKS or App Service instead.