The first request to an Azure container app times out after a quiet night
Your error
The first HTTP request after a night or weekend without traffic times out or takes far longer than usual1 more line it can showFix it fast
Most common cause, 1 of 3The app scales to zero when nobody uses it
Keep one replica running so a warm copy is always there.
az containerapp update -n my-app -g my-rg --min-replicas 1Short answer
An Azure container app whose first request of the day times out has usually scaled to zero. The minimum replica count defaults to 0, so after idle time the next request waits for an image pull and a fresh start. Set --min-replicas 1, or shrink the image and allow a longer probe. Applies to Azure Container Apps, Azure CLI 2.93.
Which cause do you have?
Look at the app's scale limits and at how many replicas are running right now, before you send the first request. A minimum of 0 and an empty replica list mean every quiet period ends with a cold start.
az containerapp show -n my-app -g my-rg --query properties.template.scale
az containerapp replica list -n my-app -g my-rg -o tableThen find the line you see in this list and open its fix:
- 1The app scales to zero when nobody uses it
minReplicas is 0 (or missing) and replica list is empty before the first request of the day - 2A large image or a far-away registry makes each cold start slow
Scale to zero is expected, but the delay on the first request is long enough to hit your client's timeout, and system logs show the image pull taking most of it - 3The app starts slowly and the health probes restart it
System logs show probe failures or the container restarting during start-up, and the first request waits through more than one start
What does the error look like?
The first HTTP request after a night or weekend without traffic times out or takes far longer than usualEvery later request answers at normal speed until the app is idle again
Cause 1 of 3
The app scales to zero when nobody uses it
You seeminReplicas is 0 (or missing) and replica list is empty before the first request of the day
Check
The first-request timeout comes from a cold start. Container Apps uses 0 as the default minimum number of replicas per revision, and once the last event is 300 seconds old (the default cool down period) KEDA removes the final replica. The next request has to wait while the platform pulls the image, provisions the replica and starts your code.
az containerapp show -n my-app -g my-rg --query properties.template.scale.minReplicasFix
Keep one replica running so a warm copy is always there. A replica that sits idle may be billed at the lower idle rate rather than the active one. If you would rather keep scale to zero, schedule a request shortly before people start work so the cold start happens before they arrive.
az containerapp update -n my-app -g my-rg --min-replicas 1Verify
replica list shows one running replica even after an hour with no traffic, and the morning request answers at normal speed.
az containerapp replica list -n my-app -g my-rg -o tableConfirmed by learn.microsoft.com
Cause 2 of 3
A large image or a far-away registry makes each cold start slow
You seeScale to zero is expected, but the delay on the first request is long enough to hit your client's timeout, and system logs show the image pull taking most of it
Check
Every cold start pulls the container image again. Microsoft names large images, heavy initialization and registries in another region as the usual reasons a cold start drags on. Compare the image size with what the app actually needs, and the registry's region with the app's region.
az containerapp logs show -n my-app -g my-rg --type system
az containerapp show -n my-app -g my-rg --query location
az acr show -n myregistry --query locationFix
Remove build tools and unused libraries from the runtime image, for example with a multi-stage build, and push it to an Azure Container Registry in the same region as the Container Apps environment. Keep large model or data files on a storage mount instead of baking them into the image.
docker build -t myregistry.azurecr.io/my-app:slim .
docker image ls myregistry.azurecr.io/my-app
docker push myregistry.azurecr.io/my-app:slim
az containerapp update -n my-app -g my-rg --image myregistry.azurecr.io/my-app:slimVerify
The system log shows a shorter pull after the next scale from zero, and the first request finishes inside your client's timeout.
az containerapp logs show -n my-app -g my-rg --type systemConfirmed by learn.microsoft.com
Cause 3 of 3
The app starts slowly and the health probes restart it
You seeSystem logs show probe failures or the container restarting during start-up, and the first request waits through more than one start
Check
With ingress enabled, the portal adds default TCP startup, liveness and readiness probes on the target port for each probe type you leave undefined. An app that loads config, warms caches or runs migrations before it opens the port can fail those checks, get restarted, and push the first answer past the client's limit.
az containerapp show -n my-app -g my-rg -o yaml > app.yamlFix
Open the listening port early and finish heavy setup after it is open, or give the container probes that allow a longer start. Edit the probes block of the container in app.yaml, then apply the file.
# in app.yaml, under properties.template.containers[0]:
probes:
- type: Liveness
tcpSocket:
port: 8080
periodSeconds: 10
failureThreshold: 3
- type: Readiness
tcpSocket:
port: 8080
initialDelaySeconds: 3
periodSeconds: 5
failureThreshold: 48
az containerapp update -n my-app -g my-rg --yaml app.yamlVerify
The system log shows the replica becoming ready once, with no restart, after a scale from zero.
az containerapp logs show -n my-app -g my-rg --type system --followConfirmed by learn.microsoft.com
How do I stop it coming back?
- Decide per app whether scale to zero is worth a slow first request, and write the chosen --min-replicas value into the deployment template so a redeploy does not reset it.
- Track the runtime image size in CI and fail the build when it grows past a limit your team picks.
- Give clients that call a scale-to-zero app a retry with a longer first timeout, and log how long each start-up stage takes inside the app.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Raheeb.