The symptom is one of these: the deployment fails, the container group shows Running but the container keeps restarting, or everything looks healthy and the app still doesn't answer on its IP or FQDN. In every case, start by reading the container's instance view. It holds the current state, the previous state, the restart count and the event list.
First checks: read the instance view
RG=rg-jobs
ACI=aci-report-runner
# Group state plus per-container state and restart count
az container show -g $RG -n $ACI \
--query "{group:instanceView.state, provisioning:provisioningState, restartPolicy:restartPolicy, containers:containers[].{name:name, state:instanceView.currentState.state, exitCode:instanceView.currentState.exitCode, detail:instanceView.currentState.detailStatus, restarts:instanceView.restartCount}}" -o json
# Events: Pulling, Pulled, Created, Started, Killing, BackOff ...
az container show -g $RG -n $ACI \
--query "containers[0].instanceView.events[].{time:lastTimestamp, type:type, name:name, message:message}" -o table
# What the app wrote to stdout/stderr
az container logs -g $RG -n $ACI --container-name <container-name>
To follow output live while you reproduce the problem:
az container attach -g $RG -n $ACI
If the container stays up long enough, open a shell in it:
az container exec -g $RG -n $ACI --container-name <container-name> --exec-command "/bin/sh"
--exec-command runs a single program with no shell parsing, so you can't pass a command line with pipes or arguments. Start a shell and type the commands inside it.
Symptom to cause
| Symptom | Likely cause | Fix |
|---|---|---|
Deployment fails with InaccessibleImage | Wrong image name or tag, missing registry credentials, identity without AcrPull, or the registry firewall blocks the pull | Check the image reference, credentials and registry network rules (below) |
| Container restarts every few seconds, exit code 0 | Image has no long-running process and restart policy is Always | Use OnFailure or Never for task-style containers, or run a foreground process |
| Container restarts, non-zero exit code | App crashes on start: missing env var, secret, config file or dependency | Read az container logs, fix the config |
| Deployment fails saying the requested resource isn't available in the location | No capacity for that CPU/memory/OS/GPU combination in the region right now | Retry later, reduce CPU/memory, or deploy to another region |
Group is Running, app not reachable | Port not exposed, app listening on 127.0.0.1, NSG or route in a VNet deployment | Check ipAddress.ports, the bind address and the subnet's NSG |
Group stuck in Pending / Waiting for a long time | Large image (Windows images especially) still pulling, or a capacity problem | Check the events for Pulling; use a smaller base image |
Terminated with OOMKilled or exit code 137 | Memory limit too small | Recreate with more --memory |
InaccessibleImage: the image pull fails
Confirm the image exists and the tag is spelled correctly:
az acr repository show-tags --name myregistry --repository report-runner -o table
Then check how the container group authenticates. Look at what was set at deployment time:
az container show -g $RG -n $ACI \
--query "{registries:imageRegistryCredentials, identity:identity}" -o json
Admin user or service principal credentials
Recreate the group with credentials. The registry login server must match the image prefix exactly:
az container create -g $RG -n $ACI \
--image myregistry.azurecr.io/report-runner:1.4.2 \
--registry-login-server myregistry.azurecr.io \
--registry-username <sp-app-id> \
--registry-password <sp-secret> \
--os-type Linux --cpu 1 --memory 1.5 \
--restart-policy OnFailure
An expired service principal secret produces the same InaccessibleImage error months after the group was first deployed, typically on a restart or redeploy.
Managed identity
Pulling with a user-assigned managed identity avoids secrets. The identity needs AcrPull on the registry:
ID_RES=$(az identity show -g $RG -n id-aci-pull --query id -o tsv)
ID_PRINCIPAL=$(az identity show -g $RG -n id-aci-pull --query principalId -o tsv)
ACR_ID=$(az acr show -n myregistry --query id -o tsv)
az role assignment create --assignee-object-id $ID_PRINCIPAL \
--assignee-principal-type ServicePrincipal --role AcrPull --scope $ACR_ID
az container create -g $RG -n $ACI \
--image myregistry.azurecr.io/report-runner:1.4.2 \
--assign-identity $ID_RES --acr-identity $ID_RES \
--os-type Linux --cpu 1 --memory 1.5 --restart-policy OnFailure
Assign the role before you create the group. If you create both at the same moment, the first pull can fail while the role assignment is still propagating.
Registry firewall and private endpoints
If the registry has public network access disabled or restricted to selected networks, a pull from ACI over the public endpoint is rejected even when the credentials are correct. Check:
az acr show -n myregistry --query "{publicAccess:publicNetworkAccess, defaultAction:networkRuleSet.defaultAction}" -o json
Options: deploy the container group into a VNet that can reach the registry's private endpoint (with the privatelink.azurecr.io zone linked), or allow the required access on the registry. Check the current ACI and ACR documentation for which network setups support pulls with managed identity, because support differs between scenarios.
Restart loops
The default restart policy for a container group is Always. A container that does its work and exits with code 0 is started again, forever. Check the policy and the exit code together:
az container show -g $RG -n $ACI \
--query "{policy:restartPolicy, exit:containers[0].instanceView.currentState.exitCode, prevExit:containers[0].instanceView.previousState.exitCode, restarts:containers[0].instanceView.restartCount}"
| Workload | Restart policy |
|---|---|
| Web server, worker that runs forever | Always |
| Batch job that should retry on failure | OnFailure |
| One-shot task, check the result yourself | Never |
Most container group properties, including the restart policy, can't be changed on a running group. Delete and recreate it:
az container delete -g $RG -n $ACI --yes
az container create ... --restart-policy OnFailure
Warning
Deleting a container group releases its public IP address. If something calls the container by IP, it breaks. Use
--dns-name-labeland call the FQDN, or put the group behind a stable endpoint such as Application Gateway.
When the exit code is non-zero, the cause is in the app. Missing environment variables are the usual one. List what the container actually received (secure values are not returned):
az container show -g $RG -n $ACI --query "containers[0].environmentVariables[].name" -o tsv
Running but not reachable
az container show -g $RG -n $ACI \
--query "{ip:ipAddress.ip, type:ipAddress.type, fqdn:ipAddress.fqdn, groupPorts:ipAddress.ports, containerPorts:containers[0].ports}" -o json
Check these in order:
- The port is listed in both the group's
ipAddress.portsand the container'sports.--ports 8080onaz container createsets both. - The app listens on
0.0.0.0, not127.0.0.1. From inside the container,netstat -tlnporss -tlnpshows the bind address if the image includes them. - For a private group (
--vnetand--subnet), the subnet must be delegated toMicrosoft.ContainerInstance/containerGroups, and its NSG and route table must allow the traffic:
az network vnet subnet show -g rg-net --vnet-name vnet-app -n snet-aci \
--query "{delegations:delegations[].serviceName, nsg:networkSecurityGroup.id, routes:routeTable.id}"
Send logs to Log Analytics
az container logs only shows the current container's output. For history across restarts and redeployments, send logs to a workspace when you create the group:
WS_ID=$(az monitor log-analytics workspace show -g rg-mon -n law-ops --query customerId -o tsv)
WS_KEY=$(az monitor log-analytics workspace get-shared-keys -g rg-mon -n law-ops --query primarySharedKey -o tsv)
az container create ... --log-analytics-workspace $WS_ID --log-analytics-workspace-key $WS_KEY
Logs and events are written to ContainerInstanceLog_CL and ContainerEvent_CL. Table and column names vary between the classic and resource-specific formats, so check what your workspace contains.
ContainerEvent_CL
| where TimeGenerated > ago(24h)
| where ContainerGroup_s == "aci-report-runner"
| project TimeGenerated, ContainerName_s, Reason_s, Message
| order by TimeGenerated desc
Prevent it next time
- Pin image tags (or digests) instead of
latest, and check that the tag exists in the pipeline before deploying. - Pull with a user-assigned managed identity that has
AcrPull, created and assigned before the container group. - Set the restart policy on purpose:
OnFailureorNeverfor jobs,Alwaysonly for long-running services. - Use a DNS name label or a fronting endpoint so you can recreate the group without breaking callers.
- Send logs to Log Analytics from the first deployment, so a crash on restart leaves evidence.
- Keep the deployment in Bicep or a script so recreating the group is routine.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get