Lesson 1 of 2 Container Hosting in Azure App Service

Understanding App Service for Containers

This lesson explains App Service plans and apps, how App Service pulls and runs a custom container, and how new image versions are released.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the relationship between plans and apps.
  • Explain the role of WEBSITES_PORT.
  • Describe how an app pulls from ACR with a managed identity.
  • Compare continuous deployment with deployment slots.

Plans and apps

Azure App Service hosts web applications, REST APIs and back ends without exposing virtual machines. Two resources work together. An App Service plan defines the compute: the region, the operating system, the pricing tier (such as Basic, Standard or Premium v3) and the number of instances. A web app is the application that runs on the plan; several apps can share one plan and its instances. Scaling up changes the plan's tier, and scaling out adds instances, manually or with autoscale rules.

App Service handles TLS termination, load balancing across instances, custom domains, managed certificates, built-in authentication, deployment slots and platform patching. For a container workload, the developer supplies only the image; App Service pulls it, starts it on each instance and routes HTTP traffic to it. This makes App Service a natural fit for an AI-backed web API that does not need the event-driven scaling of Container Apps or the control of Kubernetes.

Sort into groups

Plan or app?

Exam skills 1.1.3

Decide whether each setting belongs to the App Service plan or to the web app.

Log in to try this activity Interactive activities are free with an account.

How App Service runs a custom container

A custom container app is a Linux web app whose site configuration names an image, such as contoso.azurecr.io/infer-api:7f3c2ab. When the app starts, each instance pulls the image and runs the container, and the platform's front ends forward requests to the port on which the container listens.

  • App Service expects the container to listen on port 80 or 8080. If it listens on another port, such as 8000 for Uvicorn, set the WEBSITES_PORT app setting to that port.
  • The platform sends an HTTP request to the container during start-up and waits for a response before routing traffic. A container that takes long to start can be given more time with WEBSITES_CONTAINER_START_TIME_LIMIT.
  • Files written inside the container are lost on restart. The /home directory can be mapped to persistent shared storage with WEBSITES_ENABLE_APP_SERVICE_STORAGE=true, but application state normally belongs in a database or storage service.
  • Container output written to standard output and standard error becomes the container log, which can be streamed with az webapp log tail after logging is enabled.

Linux web apps also support sidecar containers, additional containers that run next to the main container in the same app and share its network, for tasks such as telemetry collection or a local cache. The main container remains the one that receives the app's HTTP traffic.

The following diagram compares a failed deployment of a custom container that listens on a non-default port with the corrected configuration.

Why a custom container fails to start when it listens on another port, and how to fix it. App Service sent its start-up ping to its default port 8080, while Uvicorn listens on 8000, so the container never answered. Setting the app setting WEBSITES_PORT=8000 fixes the start-up, and pulling with the app's managed identity holding AcrPull, with acrUseManagedIdentityCreds enabled, meets the rule against stored registry credentials.
Both fixes are configuration changes.
Match the pairs

Container app settings

Exam skills 1.1.3

Match each App Service setting with the problem it solves.

Log in to try this activity Interactive activities are free with an account.

Pulling from Azure Container Registry

The app needs permission to pull from a private registry. The most secure option is a managed identity: the app's system-assigned or user-assigned identity is given the AcrPull role on the registry, and the site setting acrUseManagedIdentityCreds tells App Service to pull with it. For a user-assigned identity, the acrUserManagedIdentityID setting names its client ID. No registry password is stored anywhere.

The following commands create a plan and an app from an ACR image, enable the system-assigned identity, grant it AcrPull, and switch the pull to the identity. The image tag is a unique build tag.

az appservice plan create --resource-group RG --name PLAN --is-linux --sku B1
az webapp create --resource-group RG --plan PLAN --name APP \
  --container-image-name REGISTRY.azurecr.io/infer-api:7f3c2ab
PRINCIPAL=$(az webapp identity assign --resource-group RG --name APP --query principalId -o tsv)
az role assignment create --assignee-object-id $PRINCIPAL --assignee-principal-type ServicePrincipal \
  --role AcrPull --scope $(az acr show --name REGISTRY --query id -o tsv)
az webapp config set --resource-group RG --name APP --generic-configurations '{"acrUseManagedIdentityCreds": true}'
az webapp config appsettings set --resource-group RG --name APP --settings WEBSITES_PORT=8000

The older alternative stores registry credentials in the app settings DOCKER_REGISTRY_SERVER_USERNAME and DOCKER_REGISTRY_SERVER_PASSWORD, usually the registry's admin user. It works, but it is a stored secret with full registry rights, so exam questions that ask for the most secure option point to the managed identity.

Updating the running image

A new image version can reach the app in three ways. The simplest is to change the configured image tag, which restarts the app with the new image. Continuous deployment makes App Service pull again when the registry notifies it: enabling it gives the app a webhook URL, and an ACR webhook for the repository calls that URL on each push. This suits a tag that moves, such as a staging tag, and is not appropriate where repeatable deployments by unique tag are required.

Deployment slots, available from the Standard tier, are the safest option for production. A staging slot is a separate live app with its own host name and settings. The new image is deployed to the staging slot, warmed up and tested, and then the slots are swapped: the platform switches routing so that the warmed-up instances become production with no cold start, and the previous version stays in the staging slot for an immediate swap back.

  1. Deploy to staging

    Set the staging slot's image to the new unique tag.

  2. Warm up and test

    The slot starts the container; run smoke tests against the slot's host name.

  3. Swap

    Swap staging with production; slot-specific settings stay with their slot.

  4. Roll back if needed

    Swap again to return the previous version to production.

Scenario questions

Releasing a new image

Exam skills 1.1.3

Choose how a new image version should reach each app.

Log in to try this activity Interactive activities are free with an account.
Worked example

Deploying a Python API container

A team has built a FastAPI inference API that listens on port 8000, and pushed it to ACR as infer-api:20261102.3. They deploy it to a new Linux web app, but the app shows an application error and the log reports that the container did not respond to HTTP pings on port 8080. Security policy forbids stored registry credentials.

The container started but listens on 8000, while App Service sent its start-up request to its default port. Setting the app setting WEBSITES_PORT=8000 fixes the start-up failure. To meet the security policy, the app should pull with its managed identity holding AcrPull, with acrUseManagedIdentityCreds enabled, rather than with the registry admin user.

Rebuilding the image to listen on port 80 would also work but changes code to fix a configuration issue. Adding EXPOSE 8080 to the Dockerfile only documents a port and does not change where Uvicorn listens. Increasing the start time limit would not help, because the container was never going to answer on the expected port.

Check yourself

Which site setting makes an App Service app pull from ACR with its managed identity instead of registry credentials?

Show answer

acrUseManagedIdentityCreds set to true, with the identity holding AcrPull on the registry. For a user-assigned identity, acrUserManagedIdentityID names its client ID.

Exam Tips

Remember for the exam

  • Set WEBSITES_PORT when the container listens on a port other than 80 or 8080.
  • Pull from ACR with a managed identity holding AcrPull and acrUseManagedIdentityCreds enabled.
  • Deployment slots (Standard and above) allow warm-up and swap with instant rollback.
  • Container files are lost on restart; keep state in data services.