Build and push an image with ACR Tasks
In this task you'll build an image in Azure and push it to your registry.
Azure Container Registry (ACR) stores your images privately. ACR Tasks builds them in Azure: az acr build uploads your folder, builds the Dockerfile and pushes the image, so you don't need Docker installed.
Tag every image with a real version. To stop a released version being overwritten, lock its tag.
Example. The web team at SS Kaiser builds sskaiser/shop:1.0.0 from Cloud Shell with one command, and locks the tag once it's released.
Costs money. This task creates resources that are charged while they exist. Delete them as soon as you finish.
Before you start
You need: A resource group and Contributor on it; ACR Tasks allowed on the subscription. Time: 15 minutes.
Where to look
- Home
- Container registries
- (your registry)
- Services
- Repositories
Steps
- Create a registry:
az acr create -g rg-dv-practice -n <unique name> --sku Basic.The name must be unique across Azure, letters and numbers only. - In a folder with a Dockerfile, run
az acr build -r <name> --image sskaiser/shop:1.0.0 .The final dot is the build context: the folder that's uploaded. - List what's there:
az acr repository show-tags -n <name> --repository sskaiser/shop -o table. - Lock the release:
az acr repository update -n <name> --image sskaiser/shop:1.0.0 --write-enabled false.
Commands
az group create -n rg-dv-practice -l uksouth
az acr create -g rg-dv-practice -n <uniquename> --sku Basic
az acr build -r <uniquename> --image sskaiser/shop:1.0.0 .
az acr repository show-tags -n <uniquename> --repository sskaiser/shop -o table
az acr repository update -n <uniquename> --image sskaiser/shop:1.0.0 --write-enabled false --delete-enabled false
Watch out for
- Cost
- Basic is about 13p a day; builds are billed by the second (pennies). Free trial subscriptions block ACR Tasks (error TasksOperationsNotAllowed), so
az acr build,az acr runand scheduled tasks fail until you upgrade to pay-as-you-go or ask Azure support to allow them. Importing and locking tags still work. - Security
- Keep the admin user off. Pull with managed identities (AKS attach, Container Apps identity), not passwords.
- Common mistakes
- Only pushing latest, and locking the whole repository instead of one tag.
Clean up
Delete the resource group: az group delete -n rg-dv-practice --yes --no-wait.
Words to know
- Registry
- A store for container images, such as myregistry.azurecr.io.
- Repository
- All the tags of one image name, such as sskaiser/shop.
- Tag lock
- Making one tag read-only so nobody can push a different image under it.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On