Home Microsoft AzureAzure Container Registry Tasks: Automate Image Builds

Azure Container Registry Tasks: Automate Image Builds

by Knowledge Base Linux
azure container registry tasks automated cloud image builds

Building container images on a developer laptop or a dedicated CI server works until the build environment drifts, the runner runs out of disk, or nobody can reproduce last month’s image. Azure Container Registry Tasks (ACR Tasks) move image builds into the cloud: Azure builds your Dockerfile on managed infrastructure, triggered by git commits, base image updates, or a schedule, and pushes the result straight into your registry.

This guide creates a registry, configures a build task from a GitHub repository, adds a base image update trigger, and shows how to run one-off builds without any local Docker daemon.

azure container registry tasks build trigger workflow illustration

What Azure Container Registry Tasks Do and When They Fit

ACR Tasks are a lightweight build automation service attached to your registry. Each task watches a trigger, runs a build step (usually docker build from a Dockerfile, or a multi-step YAML task), and pushes the resulting image to the same registry. There is no build agent to install, patch, or scale.

ACR Tasks fit best when your pipeline is essentially “build and push an image”: microservices with simple Dockerfiles, teams already standardized on Azure, and projects that do not need a full CI platform. If you need complex test matrices, artifact promotion gates, or deployments across many environments, a full CI/CD system such as GitHub Actions or Azure DevOps remains the better choice, and it can still push to ACR.

Prerequisites

  • An Azure subscription and Azure CLI installed (az --version) and logged in with az login.
  • A GitHub repository containing a Dockerfile at its root (a public sample repository works for learning).
  • A resource group for the registry, for example rg-containers.

Step 1: Create the Registry and Grant Build Access

Create a resource group and a Basic-tier registry:

az group create --name rg-containers --location eastus
az acr create --resource-group rg-containers \
  --name myregistry2026 --sku Basic --admin-enabled true

Verify the registry and note its login server:

az acr show --name myregistry2026 --query loginServer --output tsv

For production registries, prefer Standard or Premium tiers and disable the admin account in favor of managed identities or service principals with scoped tokens.

Step 2: Run a One-Off Cloud Build

Before automating anything, prove the build works with a quick task that builds from a remote repository without cloning it locally. This one-off run is the simplest Azure Container Registry Tasks workflow and a good smoke test for the registry itself:

az acr build --registry myregistry2026 \
  --image webapp:v1 \
  https://github.com/example/webapp.git

Azure streams the build logs to your terminal. When it finishes, list the image to confirm it landed in the registry:

az acr repository list --name myregistry2026 --output table
az acr repository show-tags --name myregistry2026 --repository webapp --output table

This single command is also the fastest way to build an image on a machine without Docker installed, such as a Chromebook or a locked-down workstation.

Step 3: Create a Task Triggered by Git Commits

A persistent task rebuilds automatically whenever code changes. Create one tied to your repository’s main branch:

az acr task create --registry myregistry2026 \
  --name build-webapp \
  --image webapp:{{.Run.ID}} \
  --context https://github.com/example/webapp.git \
  --file Dockerfile \
  --git-access-token <your-personal-access-token> \
  --branch main

The {{.Run.ID}} placeholder tags each image with its unique run identifier, giving you a traceable history of builds. Commit a change to the main branch and watch the task fire:

az acr task list-runs --registry myregistry2026 --output table
az acr task logs --registry myregistry2026 --run-id <run-id>

For private repositories, store the access token securely and rotate it on the same schedule as your other credentials. Never commit a token into the repository the task builds.

Step 4: Add a Base Image Update Trigger

Application code is not the only thing that goes stale. When your Dockerfile starts with FROM nginx:1.27, a new patch release of that base image should rebuild your image even if your code did not change. ACR Tasks can watch base images automatically:

az acr task update --registry myregistry2026 \
  --name build-webapp --base-image-trigger-enabled true

With this enabled, publishing a new base image triggers a rebuild of every dependent image, closing the window where your containers run outdated, potentially vulnerable base layers. Combine this with image scanning in your deployment pipeline for a solid supply-chain story.

Step 5: Schedule Builds and Multi-Step Tasks

Nightly rebuilds catch upstream changes that triggers miss. Add a schedule with a timer trigger:

az acr task update --registry myregistry2026 \
  --name build-webapp --schedule "0 2 * * *"

For builds that need more than one step, such as running tests before pushing, define a multi-step task in a YAML file and reference it with --file task.yaml. Multi-step tasks can build, test, and push in sequence, and they support secret volumes for build-time credentials that never appear in image layers.

Troubleshooting ACR Tasks

Task fails with authentication errors

Check the git access token’s scope and expiry first, then confirm the registry’s own credentials. Tokens for private repositories need repository read access at minimum.

Build succeeds locally but fails in ACR

Cloud builds run on a clean environment with no local cache and no files outside the build context. A Dockerfile that copies a file your .dockerignore excludes, or that depends on a local base image, will fail in the cloud while succeeding on your laptop.

Images pile up and storage costs grow

Enable retention policies or run az acr run cleanup tasks that delete untagged manifests and old tags on a schedule. Registries without retention quietly accumulate every build ever pushed.

Conclusion

Azure Container Registry Tasks remove the build server from the container workflow: commits, base image updates, and schedules all produce fresh, traceable images directly in your registry. Start with a quick build, add a git trigger, enable base image updates, and schedule a nightly rebuild for anything security-sensitive. For running those images, see our guide to deploying with Azure Container Apps, and for the storage side of Azure, Azure Blob Storage tiers. The official ACR Tasks documentation covers multi-step YAML tasks, private agent pools, and connected registries.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.