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
- Short-lived batch jobs and automation tasks.
- CI/CD pipeline steps (build agents, test runners).
- Quick proof-of-concept without setting up a Kubernetes cluster.
- Burstable workloads where you need containers for minutes to hours.
- Sidecar containers, init containers, or data processing pipelines.
ACI vs AKS vs App Service
| Feature | ACI | AKS | App Service |
|---|---|---|---|
| Startup time | Seconds | Minutes (cluster) | Seconds |
| Orchestration | None | Full Kubernetes | Built-in PaaS |
| Long-running services | Not ideal | Yes | Yes |
| Scaling | Manual | Auto (HPA/KEDA) | Auto |
| Networking | Basic + VNet | Full CNI | VNet integration |
| Cost model | Per second | Node VMs always running | Per plan tier |
| Best for | Short tasks, burst jobs | Microservices at scale | Web apps / APIs |
Commands
# 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
- Create a container group running
nginxwith a public DNS label. - Browse to
http://<dns-label>.<region>.azurecontainer.io. - Stream logs with
az container logs --follow. - Create a second container with
--restart-policy Neverto simulate a batch job. - Delete both containers and compare the per-second cost in your billing overview.
Debugging Scenario
Issue: Container exits immediately after creation.
- Run
az container logs --resource-group rg-aci --name ci-webto read application output before it exited. - Check exit code:
az container show --query "instanceView.containers[0].currentState". - Common cause: entrypoint command fails (wrong binary path, missing env var, missing file).
- Test the image locally with
docker run --rm myimagebefore deploying to ACI.
Interview Questions
Beginner
Azure Container Instances runs Docker containers on-demand without managing a cluster. Use for short-lived jobs, burst workloads, CI agents, and quick tests.
The container runs once and Azure does not restart it on exit. Ideal for batch jobs that should run exactly once.
Scenario-based
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 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.