Build and Run Images with ACR Tasks
30-second answer
ACR Tasks build, test and patch container images inside Azure Container Registry, so you don't need Docker on your machine. A quick task (az acr build) sends your folder to Azure and pushes the result. An automated task (az acr task create with --context and --file) runs on a source code commit, a base image update or a schedule. A multi-step task uses a YAML file to build, run and push several images in one go.
Exam objective: 1.1.2 Build and run images by using Azure Container Registry Tasks. (Skills measured as of October 7, 2026)
Simulations
Feel it before you read it. No account needed, nothing leaves this page.
No Docker on your laptop? Run a <strong>quick task</strong>: <code>az acr build</code> uploads the source and ACR builds and pushes it.
👆 Click the glowing item in the portal to continue
Read the steps as text
- No Docker on your laptop? Run a quick task: az acr build uploads the source and ACR builds and pushes it.
- The quick build shows up under Tasks → Runs. Now make it automatic. You create tasks from the CLI; the portal shows and runs them.
- Point the task at your GitHub repo and branch. {{.Run.ID}} gives every image a unique tag.
- Open the task. Source trigger fires on a commit to main; base image trigger fires when the Python base image is patched.
- A push to main started ca3. When Microsoft patched the base image, ca4 rebuilt your app without anyone touching it.
🧪 Simulation for learning. Screens are simplified versions of the Azure portal; names, prices and IDs are examples. Nothing here touches real Azure.
🖱️ Drag to rotate · scroll or pinch to zoom
ACR Tasks build in the cloud
ACR Tasks build the image inside Azure, so you don’t need Docker on your laptop. az acr build is a quick task. A task can also run on every git commit or when the base image (say python:3.12-slim) gets a security patch.
🤔 What happens if…
Read this tour as text
- Build an image, push it to the registry. Your Python API and everything it needs are packed into a container image. You push it to Azure Container Registry (ACR) as
ragapi:1.4.0. A tag names a version. A digest (sha256:…) names the exact bytes and never changes. - ACR Tasks build in the cloud. ACR Tasks build the image inside Azure, so you don’t need Docker on your laptop.
az acr buildis a quick task. A task can also run on every git commit or when the base image (saypython:3.12-slim) gets a security patch. - App Service runs one container. App Service pulls the image and runs it. App settings become environment variables inside the container. A setting can be a Key Vault reference, so the secret never sits in the image or in the portal in plain text.
- Container Apps environment. An Azure Container Apps environment is a secure boundary with its own virtual network and Log Analytics workspace. Several container apps share it. Ingress decides who can reach each app: external (internet) or internal (only the environment).
- Revisions and traffic splitting. Every change to the template (image, env vars, scale rules) creates a new revision, an immutable snapshot. In multiple revision mode you can send 80% of traffic to the old one and 20% to the new one, then roll forward or back.
- KEDA scales on events. Container Apps uses KEDA scale rules. A Service Bus rule adds replicas as the queue grows (for example one replica per 5 messages), up to max replicas. When the queue empties, it scales back to min replicas, which can be zero.
- AKS runs what the manifest says. On AKS you describe the app in YAML manifests: a Deployment (image, replicas, probes, resources) and a Service (a stable address).
kubectl apply -fsends them. Kubernetes keeps the real state equal to what you declared. - Troubleshoot: logs, events, connectivity. When it breaks, look in three places. Logs (
kubectl logs,az containerapp logs show) show what the app said. Events (kubectl describe,kubectl get events) show what the platform did. Connectivity checks (DNS, ports, ingress) show whether traffic can reach it.
Your chat API needs an image before it can run anywhere. Build it in Azure without Docker on your laptop, look at what landed in the registry, then set up a task that rebuilds on every commit and every base-image patch.
🎓 Education-only simulation. Your lab is saved in this browser, so you can leave and continue later.
😟 THE PROBLEM
Every developer builds images differently, and nobody patches the base image.
😊 THE SOLUTION
Let ACR Tasks build in the cloud on every commit and base-image update.
- Docker needed on every laptop✓ az acr build in the cloud
- Manual rebuilds✓ Commit triggers
- Unpatched base images✓ Base image update triggers
Start with a question
Who rebuilds your app when Python gets a security patch?
Your image is built on python:3.12-slim. Next Tuesday a security fix lands in that base image. Your code didn’t change, so nobody rebuilds, and production keeps running the old, vulnerable layers for months.
ACR Tasks can watch for that. They build images inside Azure Container Registry when you push code, when the base image changes or on a timer, so patched images appear without anyone remembering to do it.
Explain it like I’m 10
The technical explanation
Quick task: build in the cloud
Run it from the folder that holds your Dockerfile. The final . is the build context the CLI uploads.
az acr build --registry myreg --image ragapi:1.4.0 .
# Unique tag per run, and a Dockerfile that isn't at the root
az acr build --registry myreg --image 'ragapi:{{.Run.ID}}' --file docker/Dockerfile .
The logs stream to your terminal and the image lands in the registry. There’s also az acr run --registry myreg --cmd 'myreg.azurecr.io/ragapi:1.4.0' /dev/null to run a container in the task environment, which is handy for a smoke test.
Automated task: build on a trigger
az acr task create \
--registry myreg \
--name build-ragapi \
--image 'ragapi:{{.Run.ID}}' \
--context https://github.com/contoso/ragapi.git#main \
--file Dockerfile \
--git-access-token $GITHUB_PAT
That one task now has three ways to start:
| Trigger | What starts it | Flag |
|---|---|---|
| Source code commit | A push to the branch in --context | --commit-trigger-enabled (on by default) |
| Base image update | The FROM image is updated in its registry (ACR, Docker Hub, MCR) | --base-image-trigger-enabled (on by default) |
| Schedule | A cron expression, in UTC | --schedule "0 2 * * *" or az acr task timer add |
Pull request builds can be turned on with --pull-request-trigger-enabled true. Run a task by hand with az acr task run --registry myreg --name build-ragapi, and see history with az acr task list-runs and az acr task logs.
-
1 Upstream patch
python:3.12-slim gets a new digest.
-
2 Trigger
ACR notices the base image update for build-ragapi.
-
3 Rebuild
The task rebuilds your Dockerfile on the patched base.
-
4 Push
A new ragapi tag is pushed, ready to deploy.
Multi-step task: build, test, push
# acr-task.yaml
version: v1.1.0
steps:
- build: -t $Registry/ragapi:{{.Run.ID}} .
- cmd: $Registry/ragapi:{{.Run.ID}} python -m pytest -q
- push:
- $Registry/ragapi:{{.Run.ID}}
Run it once with az acr run --registry myreg -f acr-task.yaml ., or save it as a task: az acr task create --registry myreg --name ci-ragapi --context https://github.com/contoso/ragapi.git#main --file acr-task.yaml --git-access-token $GITHUB_PAT. If the cmd step fails, the push never happens.
Architect level Keeping base image triggers under your control
Pointing FROM straight at Docker Hub means any upstream change rebuilds your app, and rate limits can fail builds. A common pattern is two tasks: one imports or builds your own base (myreg.azurecr.io/base/python:3.12-slim) and runs its tests, and the app task’s FROM points at that internal base. The app’s base image trigger then fires only after your base passed its checks. Task runs authenticate to the registry automatically; to reach another registry or Key Vault from a task, give the task a managed identity with --assign-identity.
Real-world business scenario
Contoso Retail (fictional)
- The problem
- Developers built the product-search API on their laptops, some on ARM Macs and some on Windows, and pushed by hand. A security scan found base image CVEs that were months old.
- What they used
- An ACR task with --context on the GitHub main branch and the base image trigger on, plus a multi-step YAML that runs pytest before pushing a {{.Run.ID}} tag.
- Why that choice
- Builds now happen in one place on linux/amd64, tests gate every push, and base image patches rebuild the app automatically.
- The result
- No more laptop builds in production, and base image fixes reach the registry within hours of release.
When to use it and when not to
✓ Use it when…
- You want cloud builds without Docker on developer machines or build agents.
- Images should rebuild when the base OS or runtime is patched.
- A simple build, test and push flow is enough and you want it next to the registry.
✕ Think twice when…
- Complex release pipelines with approvals and multi-stage deployments across environments.
- Builds that need large custom tooling the task environment doesn't have.
↔ Alternatives to consider
- GitHub Actions or Azure Pipelines for full CI/CD with approvals, which can still call az acr build.
- az containerapp up --source to build and deploy a container app in one step.
Test yourself with exercises
5 original practice questions in the AI-200 style. Pick your answers, then check them. You will see why each option is right or wrong. Score 75% or more and this topic is marked complete.
Interview preparation
Say your answer out loud first, then open the model answer. Interviewers care more about your reasoning than the exact words.
Beginner What does az acr build do that docker build doesn't?
Model answer
It runs the build in Azure instead of on my machine. The CLI uploads my build context, ACR builds it on its own compute and pushes the image straight into the registry. I don't even need Docker installed, which helps on locked-down laptops and in Cloud Shell.
Intermediate How do you rebuild an image automatically when someone pushes to main?
Model answer
I create a task with az acr task create, pass the GitHub repo as --context with #main, the Dockerfile as --file and a personal access token with --git-access-token. The commit trigger is on by default, so ACR adds a webhook and builds on every push to that branch.
Interviewer follows up
And tagging?
You
I use {{.Run.ID}} in the image name so every build gets a unique tag, and sometimes push latest as well for dev.
Experienced developer Why does the base image update trigger matter for security?
Model answer
Because most CVEs in our images live in the base OS layers, not our code. When python:3.12-slim gets patched upstream, the trigger rebuilds our app image on top of it without anyone remembering to do it. Paired with importing the base into our own ACR, we also control when that happens.
Scenario You need to build an API image, run its unit tests in a container and push only if the tests pass. How?
Model answer
A multi-step task. In acr-task.yaml I build the image, add a cmd step that runs pytest inside it, then a push step. Steps run in order, so a failing test stops the run before anything is pushed.
Quick revision
Key points
- az acr build is a quick task that builds in the cloud and pushes to the registry.
- az acr task create saves a task; --context is the git repo or folder and --file is the Dockerfile or YAML.
- Triggers are source code commit, base image update and schedule (cron, UTC).
- Multi-step tasks use a YAML file with build, cmd and push steps; run them with az acr run -f.
- {{.Run.ID}} gives every build a unique tag.
Important terminology
- Quick task
- A one-off cloud build started with az acr build, the cloud version of docker build plus docker push.
- Automated task
- A saved task created with az acr task create that runs when a trigger fires.
- Base image update trigger
- Reruns a task when the image in the Dockerfile FROM line is updated in its registry.
- Multi-step task
- A task defined in a YAML file with build, cmd and push steps that run in order.
- Run ID
- A unique ID ACR gives every task run, available as {{.Run.ID}} for tagging images.
Common mistakes
- Forgetting the trailing dot (the build context) in az acr build.
- Expecting a schedule in local time; ACR task timers use UTC cron expressions.
Exam tips
- "Build without Docker installed" = az acr build.
- "Rebuild when the OS or runtime base image is patched" = base image update trigger.
- "Build, test and push in one definition" = multi-step task (YAML).
Five quick revision questions
-
1.Which command runs a quick task?Show
az acr build
-
2.Which parameter of az acr task create points at the git repository?Show
--context
-
3.Name the three task trigger types.Show
Source code commit, base image update and schedule.
-
4.How do you run a multi-step YAML task once?Show
az acr run -f acr-task.yaml
-
5.Which placeholder gives every build a unique tag?Show
{{.Run.ID}}
Official references
Finished this lesson? Tick it off. Your progress is saved in this browser.
Next up: Run a Container on App Service with Settings and Secrets
Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges.