Your profile

One profile for every MSDEVBUILD site. Only you can see it, and the site owner if you write in.

Lesson 3 of 28
❮Prev Next❯

Build and Run Images with ACR Tasks

Module 1: Containers ⏱ 9 min read Updated

Your note

My notes for this lesson

Select any text in the lesson to highlight it or add a note. Saved in this browser.

    No highlights yet. Select a sentence in the lesson, then pick a colour or add a note.

    All my bookmarks and notes

    Reading settings

    For every lesson, saved in this browser.

    Text size
    Line spacing
    Font

    With IaaS you rent the virtual machine. Microsoft looks after the building, power and hardware; you patch the operating system.

    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.

    Simulate it » No Azure account needed

    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.

    Azure portal: Build in the cloud with ACR Tasks Run a quick build and set up a task that triggers on commits.
    </> Embed

    Embed this simulation

    Free for trainers, teachers and bloggers. Paste this into your page:

    Loading the portal…

    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
    1. No Docker on your laptop? Run a quick task: az acr build uploads the source and ACR builds and pushes it.
    2. The quick build shows up under Tasks → Runs. Now make it automatic. You create tasks from the CLI; the portal shows and runs them.
    3. Point the task at your GitHub repo and branch. {{.Run.ID}} gives every image a unique tag.
    4. Open the task. Source trigger fires on a commit to main; base image trigger fires when the Python base image is patched.
    5. 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.

    😟 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
    🛠️ Solved with: ACR Tasks

    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:

    TriggerWhat starts itFlag
    Source code commitA push to the branch in --context--commit-trigger-enabled (on by default)
    Base image updateThe FROM image is updated in its registry (ACR, Docker Hub, MCR)--base-image-trigger-enabled (on by default)
    ScheduleA 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. 1 Upstream patch

      python:3.12-slim gets a new digest.

    2. 2 Trigger

      ACR notices the base image update for build-ragapi.

    3. 3 Rebuild

      The task rebuilds your Dockerfile on the patched base.

    4. 4 Push

      A new ragapi tag is pushed, ready to deploy.

    A base image patch, end to end

    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

    Retail

    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.
    Ready for more?The full lesson adds the technical explanation, when to use it, interview questions and revision notes.

    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.

    Question 1

    Question 1 of 5

    A developer works on a computer that does not have Docker installed. The developer needs to build the Dockerfile in the current folder and push the image to the registry contosoacr as ragapi:v1. Which command should the developer run?

    Question 2

    Question 2 of 5

    You must configure Azure Container Registry to rebuild an application image automatically when its base image, python:3.12-slim, receives a security update. What should you configure?

    Question 3

    Question 3 of 5 · Select 2

    You run the following command to create an ACR task: az acr task create --registry contosoacr --name build-api --image api:{{.Run.ID}} --context https://github.com/contoso/api.git#main --file Dockerfile --git-access-token $GITHUB_PAT. Which TWO events will start the task by default?

    Question 4

    Question 4 of 5

    You need a single ACR task definition that builds an image, runs unit tests inside the built container, and pushes the image only if the tests succeed. What should you create?

    Question 5

    Question 5 of 5

    In the az acr task create command, what is the purpose of the --context parameter?

    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. 1.Which command runs a quick task?Show

      az acr build

    2. 2.Which parameter of az acr task create points at the git repository?Show

      --context

    3. 3.Name the three task trigger types.Show

      Source code commit, base image update and schedule.

    4. 4.How do you run a multi-step YAML task once?Show

      az acr run -f acr-task.yaml

    5. 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

    Studying with a friend? Send them this lesson

    It's free and needs no sign-up. Their progress saves in their own browser.

    Lesson done? Make it stick with a quick gameSort It, Match the Pairs, Lightning Round and Who Am I? Earn XP and badges. Play ❯

    Install MSDEVBUILD Azure

    Free · no account · works offline

    Save the whole course for offline ›

    Hi, I’m your Nimbus

    Your study buddy. Pick what we do next.

    MSDEVBUILD · Multi-Stack Dev Build

    Sign in to MSDEVBUILD

    One account for Azure certifications and the blog: sign in here and you are signed in on both. Your XP, streak, practice deck and certificate stay in sync on every device. Optional: everything works without an account.