Lesson 1 of 2 Building Images with ACR Tasks

Building Images with Quick Tasks

This lesson explains how ACR Tasks builds images in Azure on demand, which build contexts and platforms it supports, and where run logs are kept.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain when a cloud build is needed.
  • Describe what az acr build and az acr run do.
  • Identify build context locations and platform options.
  • Describe how to find run logs.

Why build in the cloud

A local image build needs a Docker engine, enough disk space for base images, and network bandwidth to push the result. Several environments in an AI back-end workflow lack one or more of these: Azure Cloud Shell has no Docker engine, some locked-down developer workstations forbid it, and build agents may be shared. Large images also take a long time to push from a slow connection.

ACR Tasks solves this by running the build on Azure compute next to the registry. The client uploads only the build context, the registry builds the image and pushes it to itself, and nothing large travels over the client's connection. Because the task runs as part of the registry, it also has natural access to base images stored there.

Running a quick task

A quick task is a single on-demand build, started with az acr build. It takes the same arguments as docker build plus the registry name, and by default it pushes the image when the build succeeds.

az acr build --registry REGISTRY --image orders-api:{{.Run.ID}} --image orders-api:dev .

The final dot is the build context: the folder whose files are uploaded and made available to the Dockerfile. The Dockerfile is taken from the context root unless --file names another one. The command streams the build log to the console, and the run gets an ID such as ca12; the run variable {{.Run.ID}} places that ID in a tag, so every build has a unique tag. Several --image options push several tags for one build, for example a unique tag and a moving development tag. The --no-push option builds without pushing, which is useful for validating a Dockerfile.

az acr run is the general form. It runs a single command in a container, such as az acr run --registry REGISTRY --cmd '$Registry/orders-api:dev pytest' /dev/null, or a multi-step YAML file. Quick tasks are not saved as resources; the history of their runs is.

True or false

Quick tasks

Exam skills 1.1.2

Decide whether each statement about <code>az acr build</code> and <code>az acr run</code> is true.

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

Build contexts and platforms

The context does not have to be a local folder. ACR Tasks accepts several context locations, which lets a build run from source control without cloning it first.

ContextExampleTypical use
Local folder. or ./srcDeveloper inner loop and Cloud Shell
Git repositoryhttps://github.com/contoso/api.git#main:srcBuild a branch, commit or subfolder without cloning
Remote tarballhttps://host/app.tar.gzPackaged sources from another system
OCI artifactoci://REGISTRY.azurecr.io/src:1Sources stored as an artifact in the registry

Builds produce linux/amd64 images by default. The --platform option builds for other targets, such as linux/arm64 for Arm-based nodes or windows/amd64. A host that runs on a different architecture from the image fails to start the container, often with an exec format error, so the platform must match the target node pool or plan.

The following diagram traces a developer's build of an Arm64 image from Azure Cloud Shell, which has no Docker engine, to an Arm64 node pool.

Building an Arm64 image from Azure Cloud Shell, which has no Docker engine. The developer first validates the build with az acr build --no-push, then builds in ACR with --platform linux/arm64 and the unique tag svc:{{.Run.ID}}, and the Arm64 node pool pulls that tag. Running docker build fails in Cloud Shell, and omitting --platform would produce an amd64 image that cannot start on Arm64 nodes.
The build runs in ACR, so Cloud Shell needs no Docker engine.

Free credit subscriptions

Microsoft has temporarily paused ACR task runs for subscriptions that rely on Azure free credits. Builds in such subscriptions fail until a paid subscription is used, which matters when following labs.

Match the pairs

Build contexts

Exam skills 1.1.2

Match each build context with an example of it.

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

Logs, run history and agent pools

Every run is recorded. az acr task list-runs shows recent runs with their status, trigger and duration, and az acr task logs --run-id ID shows the log of a past run; automatically triggered runs store their logs without streaming them. Run logs are the first place to look when a build fails, because they show each Dockerfile step and its output.

By default tasks run on shared Azure compute. A Premium registry can use a dedicated agent pool (in preview), which runs tasks on dedicated machines that can be placed in a virtual network, for builds that must reach private package feeds or that need consistent capacity.

Keep secrets out of build commands

Information on the command line or in a URI can be written to ACR diagnostic logs. Never pass passwords or tokens as plain build arguments; use secret-aware task features or managed identities instead.

Scenario questions

Runs, logs and agents

Exam skills 1.1.2

Choose where to look, or what to use, for each build situation.

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

Building without Docker

A developer works in Azure Cloud Shell and must build a FastAPI service for an AKS node pool that runs on Arm64 virtual machines. Each build must have a unique tag, and the developer wants to check that the Dockerfile builds before pushing anything.

The developer first runs az acr build --registry REGISTRY --image svc:check --platform linux/arm64 --no-push . to validate the build. Once it succeeds, the same command without --no-push and with --image svc:{{.Run.ID}} builds and pushes an Arm64 image with a unique tag. Cloud Shell needs no Docker engine, because the build runs in ACR.

Running docker build fails in Cloud Shell. Building without --platform would produce an amd64 image that cannot start on Arm64 nodes. Using a fixed tag such as latest would lose the unique, traceable version.

Check yourself

A build produced by az acr build fails to start on Arm64 nodes with an exec format error. What is the likely cause?

Show answer

ACR Tasks builds linux/amd64 by default. The build needs --platform linux/arm64 so that the image matches the nodes' architecture.

Exam Tips

Remember for the exam

  • az acr build builds in Azure and pushes by default; no local Docker engine is needed.
  • {{.Run.ID}} gives every build a unique tag.
  • The default platform is linux/amd64; match --platform to the target nodes.
  • Run logs are kept for every run and read with az acr task logs.