Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/container-apps/day2-operations.md
1# Container Apps Day-2 Operations23Operational tasks for running Container Apps in production: restart, exec, logs, environment updates, and secret rotation.45## Restart and Lifecycle67| Action | Command |8|--------|---------|9| Restart active revision | `az containerapp revision restart -n $APP -g $RG --revision $REV` |10| Scale to zero (stop) | `az containerapp update -n $APP -g $RG --min-replicas 0 --max-replicas <current-max>` |11| Resume (restore scaling) | `az containerapp update -n $APP -g $RG --min-replicas <previous-min> --max-replicas <current-max>` |12| List replicas | `az containerapp replica list -n $APP -g $RG --revision $REV` |1314> ๐ก **Tip:** Restarting a revision replaces all running replicas gracefully. No new revision is created.1516## Exec into a Container1718Open a shell inside a running replica for debugging:1920```bash21# Interactive shell22az containerapp exec -n $APP -g $RG --command /bin/sh2324# Target a specific replica and container25az containerapp exec -n $APP -g $RG \26--replica $REPLICA_NAME \27--container $CONTAINER_NAME \28--command /bin/sh29```3031> โ ๏ธ **Warning:** Exec sessions are for debugging only. Changes to the container filesystem are lost on restart.3233## Log Streaming3435### Real-time Logs3637```bash38# Stream system logs39az containerapp logs show -n $APP -g $RG --type system --follow4041# Stream application (console) logs42az containerapp logs show -n $APP -g $RG --type console --follow4344# Filter to a specific revision or replica45az containerapp logs show -n $APP -g $RG \46--type console --revision $REV --follow47```4849### Log Analytics (KQL)5051Query historical logs via the Container Apps environment's Log Analytics workspace:5253```kql54// Azure Monitor destination (new environments โ default)55ContainerAppConsoleLogs56| where ContainerAppName == "my-app"57| where TimeGenerated > ago(1h)58| project TimeGenerated, Log, RevisionName59| order by TimeGenerated desc6061// Log Analytics destination (legacy environments)62// ContainerAppConsoleLogs_CL63// | where ContainerAppName_s == "my-app"64// | project TimeGenerated, Log_s, RevisionName_s65```6667## Environment Variable Updates6869Updating environment variables creates a new revision:7071```bash72# Set or update env vars73az containerapp update -n $APP -g $RG \74--set-env-vars "DB_HOST=newhost.postgres.database.azure.com" \75"CACHE_TTL=300"7677# Remove an env var78az containerapp update -n $APP -g $RG \79--remove-env-vars "OLD_SETTING"80```8182### Bicep โ Env Vars with Secret References8384```bicep85configuration: {86secrets: [87{ name: 'db-password', value: dbPassword } // or use keyVaultUrl + identity88]89}90template: {91containers: [92{93name: 'api'94image: '${acrName}.azurecr.io/api:latest'95env: [96{ name: 'DB_HOST', value: dbHost }97{ name: 'DB_PASSWORD', secretRef: 'db-password' }98]99}100]101}102```103104## Secret Management105106### Create and Update Secrets107108```bash109# Add a secret (use Key Vault references in production โ avoid plaintext secrets)110az containerapp secret set -n $APP -g $RG \111--secrets "db-password=<secret-value>"112113# Reference a Key Vault secret (managed identity required)114az containerapp secret set -n $APP -g $RG \115--secrets "db-password=keyvaultref:https://myvault.vault.azure.net/secrets/db-pwd,identityref:/subscriptions/.../userAssignedIdentities/my-id"116```117118> โ ๏ธ **Warning:** Avoid passing plaintext secrets on the command line โ they may appear in shell history and process listings. Prefer Key Vault references. If you must use plaintext, use shell substitution like `--secrets "key=$(cat secret.txt)"` to avoid literals on the command line.119120> ๐ก **Tip:** Use Key Vault references instead of plain-text secrets. The Container App pulls the latest value on each new revision or replica start.121122### Secret Rotation Workflow1231241. Update the secret value in Key Vault1252. Create a new revision to pick up the updated value:126```bash127az containerapp revision copy -n $APP -g $RG128```1293. Verify the new revision is healthy1304. Shift traffic to the new revision131132> โ ๏ธ **Warning:** Existing replicas do NOT hot-reload Key Vault references. A new revision or replica restart is required.133134## Health Monitoring135136| Check | How |137|-------|-----|138| Revision health | `az containerapp revision list -n $APP -g $RG -o table` |139| Replica status | `az containerapp replica list -n $APP -g $RG --revision $REV` |140| System logs | `az containerapp logs show -n $APP -g $RG --type system` |141| Metrics | Azure Monitor โ Container Apps โ Requests, Replicas, CPU, Memory |142143## Common Troubleshooting144145| Symptom | Likely Cause | Remediation |146|---------|-------------|-------------|147| Replica crash loop | App startup failure | Check console logs; exec into container |148| 0 replicas running | Scale-to-zero + no traffic | Set `minReplicas: 1` or send a request |149| Env var not updating | Old revision still serving traffic | Verify the latest revision exists, then update ingress traffic weights or route to `latestRevision` |150| Secret value stale | Key Vault ref not refreshed | Create or verify the refreshed revision, then shift traffic to that revision |151| High memory/CPU | Resource limits too low | Update `resources.cpu` / `resources.memory` |152