↑ ↓ to move, Enter to open, Esc to close

    AI-200Developing AI Cloud Solutions on Azure

    Switch exam

    Microsoft Azure

    aws Amazon Web Services

    Google Cloud

    ServiceNow

    Databricks

    Cisco

    Salesforce

    All exams and search

    Exams / AI-200 / D1 Develop containerized solutions on Azure

    D1.1

    Implement container application hosting

    • 5 min read
    • 5 sections
    • 12 questions
    • 20–25% of the exam
    • Free preview
    • Build, store, version, and manage container images by using Azure Container Registry
    • Build and run images by using Azure Container Registry Tasks
    • Deploy containers to Azure App Service, including configuring App Service to supply environment variables and secrets
    You are reading a free preview. The rest of the AI-200 course unlocks with an Exam pass or All access.See plans

    Azure Container Registry (ACR): what you address

    Term Meaning Exam signal
    Registry The service: myregistry.azurecr.io (login server, always lowercase, no port) —
    Repository Images with the same name and different tags (web:v1, web:v2); namespaces are just / in the name —
    Tag Mutable version label; latest is used when none is given "tags can change later" → don't rely on a tag
    Manifest digest Unique SHA-256 of one build; every image has one, tagged or not "identical build", "immutable" → pull or deploy by digest

    Addressing: by tag myregistry.azurecr.io/web:v2, by digest myregistry.azurecr.io/web@sha256:….

    Tagging strategy: stable tags (node:20) for base images that receive patches, unique tags (build ID, commit SHA, date) for anything you deploy. Pushing the same tag repeatedly leaves untagged orphans that still use storage.

    Authenticating to ACR

    Method Use it for Notes
    Individual Entra ID: az acr login Developer push/pull Token valid 3 hours; uses Docker to store it
    Service principal Headless CI/CD outside Azure RBAC roles; password expires
    Managed identity Azure services pulling or pushing (App Service, ACA, AKS, ACR Tasks) No secret to store or rotate
    Admin user Single-user testing only Disabled by default, full push+pull, not RBAC — the wrong answer whenever "no static credentials" or "least privilege" appears

    Pull role: AcrPull on a classic registry, Container Registry Repository Reader on an ABAC-enabled registry. Push: AcrPush (or the ABAC writer role).

    ACR Tasks

    Triggersaz acr build(quick task, on demand)Git commit / pull request(webhook in the repo, PAT)Base image updated(ACR or Docker Hub)Timer (cron)ACR Tasks agentbuilds in AzurePush tomyregistry.azurecr.io
    Kind Command When
    Quick task az acr build -r myregistry -t web:{{.Run.ID}} . "docker build + push in the cloud", no local Docker Engine
    Automatically triggered task az acr task create --context https://github.com/org/repo.git --file Dockerfile --git-access-token <PAT> Commit (on by default), pull request (off by default), base image update, timer (--schedule)
    Multi-step task az acr task create --file task.yaml Build → run → test → push → Helm, defined in YAML
    • Source triggers need a personal access token so the task can create the webhook in the GitHub / Azure DevOps repo. Not supported for GitHub Enterprise repos.
    • Base image update: the task records the base image dependency at build time and rebuilds when that base is updated in the same registry, another registry, or a public repo such as Docker Hub. This is how you automate OS and framework patching.
    • Task logs: streamed when you start a run manually, only stored when it was triggered automatically (az acr task logs).

    Cross-registry base image (base in registry B, task in registry A)

    1. az acr build -r baseregistry … (or az acr import): the base image exists in B.
    2. az acr task create -r registryA … --assign-identity: the task gets a managed identity.
    3. az role assignment create --assignee <task identity> --scope <B id> --role AcrPull: the identity can pull from B.
    4. az acr task credential add -r registryA --login-server baseregistry.azurecr.io --use-identity [system]: the task uses that identity for B.
    5. az acr task run: verify.

    Dockerfile essentials

    Instruction Runs Role
    FROM build Base image of the stage
    WORKDIR build Directory for the following instructions
    COPY / ADD build Bring files from the build context
    RUN build Execute a command and commit the result as a layer
    CMD / ENTRYPOINT container start Default command of the running container

    Typical order: FROM → WORKDIR → COPY → RUN → CMD. Modern .NET base images live on mcr.microsoft.com/dotnet/aspnet (old microsoft/aspnetcore names still appear in questions).

    Custom containers on Azure App Service

    Pull from ACR with a managed identity

    1. az webapp identity assign (system- or user-assigned).
    2. az role assignment create --role AcrPull --scope <registry id>.
    3. az webapp config set --generic-configurations '{"acrUseManagedIdentityCreds": true}' (plus acrUserManagedIdentityID for a user-assigned identity).

    The registry must accept ARM-audience tokens, otherwise pulls fail with UNAUTHORIZED. Using registry username/password (--docker-registry-server-user/password) is the legacy path.

    Settings, environment variables and secrets

    • App settings and connection strings are injected into the container as environment variables. Check them at https://<app>.scm.azurewebsites.net/Env.
    • WEBSITES_PORT: the port your container listens on when it isn't 80.
    • WEBSITES_ENABLE_APP_SERVICE_STORAGE=true: persist /home on Linux custom containers (off by default).
    • Secrets → Key Vault references as the value of an app setting or connection string:
      • @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret)
      • @Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret)
    • The app's managed identity needs Key Vault Secrets User (RBAC) or Get on secrets (access policy). System-assigned identity is used by default; set keyVaultReferenceIdentity for a user-assigned one.
    • No version in the reference → the app picks up rotated secrets automatically, within 24 hours (cache), or immediately on restart or config change.
    • Never: ENV in the Dockerfile, secrets in source control, GitHub secrets for runtime values.

    Container logs

    az webapp log config --name <app> --resource-group <rg> --docker-container-logging filesystem
    az webapp log tail   --name <app> --resource-group <rg>
    

    Docker host (platform) logs are on by default; container STDOUT/STDERR needs --docker-container-logging. Docker Compose multi-container apps retire on March 31, 2027 (sidecars replace them).

    Exam traps

    • "Same build even if tags change": digest, not production or latest.
    • ACR Tasks triggers are commit/PR, base image update and timer. "Registry event" and ACR webhooks don't build anything.
    • Quick task = az acr build, on demand. Commit-triggered = az acr task create with a Git context (+ PAT; the webhook lives in the repo).
    • "Rebuild when the OS/base image is patched", even from Docker Hub: base image update trigger.
    • "Build must run inside ACR / no external build service": ACR Tasks, not GitHub Actions or Azure Pipelines.
    • Cross-registry base image: task identity + az role assignment create on the other registry + az acr task credential add --use-identity.
    • Admin user is never the secure answer. App Service pulls ACR images with a managed identity + AcrPull (Container Registry Repository Reader when ABAC is on).
    • App setting = environment variable. Secret = app setting whose value is a Key Vault reference.
    • RUN happens at build time, CMD at container start.
    • Live container logs: az webapp log config --docker-container-logging filesystem, then az webapp log tail.

    Docs

    The rest of this chapter is part of the AI-200 premium course

    Unlock every chapter, all 153 questions and spaced review with All access or a 90-day exam pass. Every Fundamentals exam stays free, and the first chapter of every exam is open.

    Chapters