CI/CD on Azure · Part 3 of 7
Azure Container Registry
Creating a private container registry on Azure, a tagging strategy, and a first manual push of the image to validate the chain end to end before automating it.
- Azure
- ACR
- PowerShell
What is a container registry?
A container registry is a central store for keeping and distributing Docker images. If Docker Hub is the public equivalent (like GitHub for code), Azure Container Registry (ACR) is its private equivalent, hosted in your Azure tenant.
The analogy with an RPM or APT package repository holds up well: you publish versioned artifacts to it, you fetch them from any authorized environment, and you keep a history of versions. The difference is that the artifact is not a package but a full Docker image: the application and its runtime environment together.
In our pipeline, ACR acts as the single source of truth for images meant for a containerized deployment:
- GitHub Actions pushes an image to it after each build of the
stagingbranch - Azure Container Apps pulls it from ACR at deployment time
- Nobody builds an image directly on a target server, we always deploy from the registry
One point to keep in mind: ACR only comes into play for the staging environment. The dev branch stays strictly local (see article 1), and production never consumes an image. Azure Static Web Apps directly deploys the out/ folder generated by next build, without going through Docker or a registry. So ACR is not the universal crossing point of the whole pipeline, only that of its single containerized step.
Why ACR rather than Docker Hub?
Docker Hub is public by default, and going private is paid beyond one repository. Above all, for an Azure deployment, ACR offers native integration:
- Transparent authentication: Azure services (Container Apps, AKS) can connect to ACR through managed identities, with no password to manage
- Private network: traffic between ACR and Azure services can stay on Azure’s internal network, without going over the Internet
- Location: ACR is deployed in the same region as your other resources, which guarantees minimal latency on pull
- Retention and cleanup: retention policies can automatically delete old images to keep storage costs under control
Creating the ACR
All the following operations are done with PowerShell. It is a purely personal choice, the Azure CLI does the job just as well.
Docker commands, for their part, stay in bash since they run in my usual WSL2 environment; the two contexts live side by side naturally on a Windows machine.
Prerequisites
# Check that the Az module is installed and up to date
Get-InstalledModule -Name Az
# Sign in to Azure (opens an interactive sign-in window)
Connect-AzAccount
# Check that we are on the right subscription
Get-AzContext | Select-Object Name, Subscription
# If needed, switch to the right subscription, here "Root subscription"
Set-AzContext -Subscription "Root subscription"
# Register the ACR resource provider
Register-AzResourceProvider -ProviderNamespace Microsoft.ContainerRegistryWorking variables
$rg = "rg-westbalidrivers"
$location = "westeurope"
$acr_name = "acrwestbalidrivers" # must be globally unique, no dashes or capitals
$sku = "Basic" # Basic is plenty for a project like this oneA note on the SKU: ACR comes in three tiers: Basic, Standard, Premium. Basic offers 10 GB of storage and is plenty for a solo project or a small team. Standard (100 GB, geo-replication possible) and Premium (multi-region replication, private network) are suited to enterprise projects. Basic costs a little under €5/month.
Creating the Resource Group (if it does not exist)
New-AzResourceGroup -Name $rg -Location $locationCreating the ACR
$registry = New-AzContainerRegistry -ResourceGroupName $rg -Name $acr_name -Sku $sku
# The admin account (static login/password) stays disabled by default.
# We will authenticate through Connect-AzContainerRegistry, backed by an Azure identity,
# rather than through a fixed username/password pair.Check:
Get-AzContainerRegistry -ResourceGroupName $rg -Name $acr_name | Select-Object Name, LoginServer, @{Name = 'Sku'; Expression = {$_.SkuTier}}Name LoginServer Sku
-------------------- ----------------------------------- -----
acrwestbalidrivers acrwestbalidrivers.azurecr.io BasicThe acrwestbalidrivers.azurecr.io address is the endpoint Docker will push images to and pull them from.
Tagging strategy
Before pushing our first image, we need a naming convention. Docker tags are the equivalent of package versions: they identify precisely which image is deployed where.
Here, the convention is simpler than it could have been, precisely because a single environment consumes images from ACR:
| Tag | Triggered by | Deployed to |
|---|---|---|
staging | Push to the staging branch | Azure Container Apps |
sha-abc1234 | Every CI build on staging | Kept in ACR for rollback |
The dev and main branches never push anything to ACR: dev stays local, and main triggers a direct deployment to Azure Static Web Apps from the out/ folder, with no Docker step.
The commit SHA tag still matters even with a single environment: it lets us find and redeploy an exact version of the image, independently of the moving staging tag, which always points to the latest build. It is your safety net for rollbacks.
The full format of an image reference in our ACR will be:
acrwestbalidrivers.azurecr.io/westbalidrivers:staging
acrwestbalidrivers.azurecr.io/westbalidrivers:sha-abc1234First manual push
We do this first push by hand to validate the chain end to end before automating it.
Always worth validating by hand before automating.
Reminder from the previous chapter: the image must have been built with
--build-arg NEXT_PUBLIC_MAPBOX_TOKEN=..., otherwise the Mapbox map will stay broken once deployed. This variable is injected atpnpm buildtime, not read at runtime. If you have not done so already:bashdocker build \ -f docker/Dockerfile \ --target runner \ --build-arg NEXT_PUBLIC_MAPBOX_TOKEN=the_token \ -t westbalidrivers:local \ .
Authenticating with ACR
Connect-AzContainerRegistry -Name $acr_name
# The Az module fetches a temporary token and configures Docker to use it
# (internally, this cmdlet runs a docker login with a short-lived token).
# The token is valid for 3 hours, which is enough for our manual tests.
# In CI/CD, authentication will work differently (through OIDC, chapter 5).Tagging the local image for ACR
# The image built in the previous chapter
docker tag westbalidrivers:local acrwestbalidrivers.azurecr.io/westbalidrivers:staging
# We also create the SHA tag to simulate what the pipeline will do (careful, the current shell is still PowerShell)
$git_sha=$(git rev-parse --short HEAD)
docker tag westbalidrivers:local acrwestbalidrivers.azurecr.io/westbalidrivers:sha-$git_shaPushing to ACR
docker push acrwestbalidrivers.azurecr.io/westbalidrivers:staging
docker push acrwestbalidrivers.azurecr.io/westbalidrivers:sha-$git_shaProgress is shown layer by layer. Docker only transfers the layers that are not already present in ACR, which makes subsequent pushes much faster.
Checking that the image is in ACR
# List the repositories
Get-AzContainerRegistryRepository -RegistryName $acr_name
# List the tags available for our image
Get-AzContainerRegistryTag -RegistryName $acr_name -RepositoryName "westbalidrivers"Registry ImageName Tags
-------- --------- ----
acrwestbalidrivers.azurecr.io westbalidrivers {sha-a69596f, staging}Validating by pulling the image from ACR
To make sure the image is not only present but can be pulled correctly:
# Delete the local image to force the pull from ACR
docker rmi acrwestbalidrivers.azurecr.io/westbalidrivers:staging
# Pull from ACR and run
docker run --rm -p 8080:80 acrwestbalidrivers.azurecr.io/westbalidrivers:stagingPS /home/louis/app> docker run --rm -p 8080:80 acrwestbalidrivers.azurecr.io/westbalidrivers:staging
Unable to find image 'acrwestbalidrivers.azurecr.io/westbalidrivers:staging' locally
staging: Pulling from westbalidrivers
Digest: sha256:573ed224d59d90a552b386eb45d4b30171fe14131a06cde6b515bd69c6233958
Status: Downloaded newer image for acrwestbalidrivers.azurecr.io/westbalidrivers:stagingThe site must respond on http://localhost:8080, exactly as in the local test of the previous chapter, but this time the image comes from the Azure registry.
Retention policy (optional but recommended)
Without a retention policy, every CI build pushes a new image to ACR. After a few weeks, depending on how often we push, images pile up, and the unused ones consume storage and therefore budget.
This policy is not written yet: it is left pending for now.
Checklist before moving on
- The ACR is created with
--admin-enabled false -
Connect-AzContainerRegistryworks without errors - The image was built with
--build-arg NEXT_PUBLIC_MAPBOX_TOKEN=... - The
westbalidrivers:stagingimage is visible in ACR throughGet-AzContainerRegistryTag - A
docker runfrom the ACR image responds correctly onlocalhost:8080, Mapbox map included - The retention policy is configured
Next
Our image now lives in a private Azure registry, reachable from our tenant.
In the next chapter, we will use it to create our staging environment on Azure Container Apps. The one that simulates real conditions before the site leaves, without a container this time, for Azure Static Web Apps in production.