☁ Azure Container Guide

5b. Deploy to Azure Container Apps

Run your container on a serverless platform with HTTPS ingress, revisions and autoscaling built in.

1. Install the extension

az extension add --name containerapp --upgrade

2. Create a Container Apps environment

The environment is a secure boundary around one or more apps. It also provisions a Log Analytics workspace for logs by default.

az containerapp env create \
  --name cae-containerdemo \
  --resource-group $RG \
  --location $LOCATION

3. Create the app with a managed identity for ACR

az containerapp create \
  --name ca-containerdemo \
  --resource-group $RG \
  --environment cae-containerdemo \
  --image $ACR_NAME.azurecr.io/$IMAGE:$TAG \
  --target-port 8080 \
  --ingress external \
  --registry-server $ACR_NAME.azurecr.io \
  --registry-identity system \
  --min-replicas 0 \
  --max-replicas 3
--target-port must match the port your container listens on (8080 for the .NET images). --min-replicas 0 lets the app scale to zero when idle; use 1 to avoid cold starts.

If the image pull fails, confirm the app's identity has the AcrPull role on the registry:

PRINCIPAL_ID=$(az containerapp show --name ca-containerdemo --resource-group $RG --query identity.principalId --output tsv)
ACR_ID=$(az acr show --name $ACR_NAME --query id --output tsv)
az role assignment create --assignee $PRINCIPAL_ID --role AcrPull --scope $ACR_ID

4. Get the URL

az containerapp show \
  --name ca-containerdemo \
  --resource-group $RG \
  --query properties.configuration.ingress.fqdn \
  --output tsv

5. Deploy a new version

Each update creates a new revision, so you can roll back or split traffic.

az containerapp update \
  --name ca-containerdemo \
  --resource-group $RG \
  --image $ACR_NAME.azurecr.io/$IMAGE:v2

az containerapp revision list --name ca-containerdemo --resource-group $RG --output table

6. Configuration, secrets and scaling

# Environment variable
az containerapp update --name ca-containerdemo --resource-group $RG \
  --set-env-vars "ASPNETCORE_ENVIRONMENT=Production"

# HTTP autoscale rule: add replicas at 50 concurrent requests per replica
az containerapp update --name ca-containerdemo --resource-group $RG \
  --scale-rule-name http-rule --scale-rule-type http \
  --scale-rule-http-concurrency 50