ACR Tasks: Automated Image Builds
Build, test, and patch container images in Azure without running your own build agents. Quick tasks, multi-step tasks, base-image triggers, and how Lin keeps three clients' images current with one pipeline.
What ACR Tasks is
ACR Tasks lets Azure build your container images for you. Instead of running a Docker build on your laptop or a GitHub Actions runner, you tell ACR βhereβs my Dockerfile and source β build it, push it, and trigger me again whenever the base image changes.β
Three flavours: quick tasks (one-off builds, like running docker build in the cloud), tasks (long-lived definitions that re-run on triggers), and multi-step tasks (build, test, push, deploy in a YAML file).
Why it matters for AI-200: ACR Tasks can rebuild your image automatically when a security patch lands in the base image (e.g., the day a Python CVE drops, your image rebuilds without you lifting a finger).
The three flavours
| Feature | Quick task | Triggered task | Multi-step task |
|---|---|---|---|
| Command | `az acr build` | `az acr task create` + `az acr task run` | `az acr task create -f acr-task.yaml` |
| Triggered by | Manually, from CLI | git push, base-image update, schedule, manual run | Same as triggered task; runs the YAML |
| What it does | Builds + pushes one image | Builds + pushes one image, repeatedly | Build, test, scan, push, run external commands β multiple steps |
| When to use | Replace local `docker build` for slow laptops or CI | Auto-rebuild on commits or base-image patches | Full pipeline (build β test β push β deploy webhook) |
Quick task β your daily driver
A quick task replaces docker build && docker push on your laptop. The build runs on Azure infrastructure, the result lands in your ACR, and you save the bandwidth of pushing a multi-GB image over your home internet.
# From the directory containing your Dockerfile:
az acr build \
--registry roo \
--image roo-vision:v3.4.1 \
--image roo-vision:latest \
--file Dockerfile .
The dot at the end is the build context β ACR Tasks zips the directory and uploads it. The build runs in the same region as your registry, so the resulting image push is internal and fast.
Why Mira always uses `az acr build` over `docker build`
Miraβs vision image is 4.2 GB. Building locally:
- Pull the 3.5 GB CUDA base image to her laptop (β12 minutes on home Wi-Fi)
- Run the build (8 minutes)
- Push 4.2 GB back to ACR (β18 minutes)
Total: 38 minutes, hammering her connection.
Building with az acr build:
- Upload the build context only β a few KB of Dockerfile + Python source (5 seconds)
- Build runs in the same Azure region as ACR (8 minutes)
- Push is internal Azure traffic (30 seconds)
Total: under 9 minutes, no laptop bandwidth used. ACR Tasks pays for itself the first day.
Triggered tasks β the killer feature for AI
A triggered task is a stored definition that runs whenever something changes. Three trigger types:
| Trigger | Fires when | Best for |
|---|---|---|
| Source code | Commit lands on a tracked git branch (GitHub, Azure DevOps) | Continuous delivery β every commit produces a fresh image |
| Base image update | The base image referenced in your FROM line is updated in ACR or Microsoft Container Registry | Auto-patching β Python or Ubuntu CVE β your image rebuilds within minutes |
| Timer | A cron schedule | Nightly rebuilds, weekly patch refreshes |
# Source code trigger β rebuild on every commit to main
az acr task create \
--name roo-vision-build \
--registry roo \
--image roo-vision:{{.Run.ID}} \
--image roo-vision:latest \
--context https://github.com/roo-robotics/vision \
--file Dockerfile \
--branch main \
--git-access-token $GITHUB_PAT
Note the {{.Run.ID}} template β every build gets a unique tag, plus the moving :latest.
Base-image update triggers β the security story
This is the feature youβll see most on the exam. When you reference a base image (FROM python:3.12-slim), ACR Tasks watches the upstream image. The instant a new digest is published, ACR Tasks rebuilds your downstream image and pushes a new tag. You did nothing.
# Dockerfile
FROM mcr.microsoft.com/azure-functions/python:4-python3.12
COPY . /app
RUN pip install -r requirements.txt
CMD ["python", "-m", "function_host"]
The day Microsoft ships a Python 3.12 patch, your image rebuilds automatically β assuming you created the task with --base-image-trigger Runtime (the default) and a tracked tag.
Exam tip: distinguish 'patch the OS' from 'patch the framework'
Base-image update triggers track the direct base image referenced in FROM. They do not chase the OS layer underneath that base image unless thatβs the layer you depend on.
Premium tier adds automatic OS / framework patching β ACR can patch the OS layer of an image without rebuilding from source. Thatβs a Premium-only feature; Basic and Standard cannot.
Multi-step tasks β full pipelines in YAML
When a single build isnβt enough β build, test, scan, push, then notify β multi-step tasks let you express the whole flow in a YAML file.
# acr-task.yaml
version: v1.1.0
steps:
- id: build
build: -t {{.Run.Registry}}/roo-vision:{{.Run.ID}} -f Dockerfile .
- id: test
cmd: roo/test-runner:latest
when: ["build"]
env:
- IMAGE={{.Run.Registry}}/roo-vision:{{.Run.ID}}
- id: scan
cmd: aquasec/trivy image {{.Run.Registry}}/roo-vision:{{.Run.ID}}
when: ["build"]
- id: push
push:
- {{.Run.Registry}}/roo-vision:{{.Run.ID}}
when: ["test", "scan"]
when controls dependencies β test and scan both wait on build, then push waits on both. Steps without when run in parallel.
Authentication β managed identity inside the task
ACR Tasks runs with its own identity. Assign that identity roles on whatever Azure resources the task needs:
# Create a task with a system-assigned managed identity
az acr task create \
--name nightly-build \
--registry roo \
--image worker:nightly \
--context $GIT \
--schedule "0 2 * * *" \
--assign-identity [system]
# Grant the identity AcrPush on the registry
az role assignment create \
--assignee $(az acr task show -n nightly-build -r roo --query identity.principalId -o tsv) \
--role AcrPush \
--scope $(az acr show -n roo --query id -o tsv)
The task pushes images to the registry without storing a password.
Key terms
Knowledge check
Mira's vision image is built from `FROM python:3.12-slim`. She wants the image to rebuild automatically when a Python 3.12 CVE patch is published, without anyone running a build manually. Which ACR Tasks feature should she configure?
Lin needs to run a build, run unit tests against the built image, scan it for vulnerabilities, and only push if both test and scan succeed. What's the cleanest fit in ACR Tasks?
An ACR task pushes images to its host registry. What's the recommended way for the task to authenticate to the registry?