Azure Container Registry Basics
Complete the full lesson to earn 25 points — 50 with Pro
Work through each section, then tap “Mark as Complete” on the last one.
✦ Skip the page breaks, the wait, and see fewer ads — read each lesson on a single page with Pro
Azure Container Registry: A Comprehensive Guide
Introduction: Why Container Registries Matter
In modern software development, the move toward containerization has changed how we package, distribute, and deploy applications. By using tools like Docker, developers can bundle an application along with its dependencies, libraries, and configuration files into a single unit known as a container image. However, once you have built these images on your local machine, you face a practical problem: where do you store them so that your production servers, Kubernetes clusters, or cloud-based testing environments can access them?
This is where a container registry comes into play. Think of a container registry as a private, secure, and highly available library for your software artifacts. Azure Container Registry (ACR) is Microsoft’s managed service for hosting these Docker-compatible images. It acts as the central hub for your container development lifecycle. Without a registry, you would be forced to manually copy image files between servers, which is inefficient, insecure, and prone to error.
Understanding ACR is critical because it bridges the gap between the developer’s workstation and the operational environment. It provides built-in security features, such as role-based access control (RBAC), image scanning for vulnerabilities, and geo-replication. Mastering ACR allows you to build a reliable pipeline where your code is developed, tested, packaged, and shipped to the cloud with minimal friction. This lesson will guide you through the fundamental concepts, practical operations, and industry-standard best practices for managing your container images in Azure.
What is Azure Container Registry?
Azure Container Registry is a managed, private Docker registry service based on the open-source Docker Registry 2.0. Because it adheres to the industry-standard Docker Registry API, you can use your existing Docker CLI tools to push, pull, and manage images. The primary purpose of ACR is to store and distribute container images for your Azure-based deployments, such as Azure Kubernetes Service (AKS), Azure Container Instances (ACI), or Azure App Service.
One of the defining characteristics of ACR is that it is a private service. Unlike public registries such as Docker Hub, which host open-source images for the world to see, ACR is designed for enterprise use. It integrates directly with Azure Active Directory (now Microsoft Entra ID), ensuring that only authorized users or services within your organization can access your proprietary code.
Key Features of ACR
- Private Image Storage: Keep your intellectual property secure within your own Azure tenant.
- Geo-replication: Automatically replicate your registry across multiple Azure regions to reduce latency and improve availability.
- Role-Based Access Control (RBAC): Granular control over who can pull, push, or delete images.
- Vulnerability Scanning: Integration with Microsoft Defender for Cloud to automatically scan images for known security vulnerabilities.
- Content Trust: Support for digital signatures to ensure that images are from a trusted source and have not been tampered with.
- Webhooks: Trigger events in other systems (like CI/CD pipelines) whenever an image is pushed or deleted.
Callout: Public vs. Private Registries While public registries are useful for sharing open-source components, they are generally inappropriate for proprietary business logic. Public registries expose your code to the world, making it difficult to manage security patches and access control. Azure Container Registry provides a private, walled garden where your images are encrypted at rest and accessed only via secure, authenticated channels.
Getting Started with Azure Container Registry
Before you can store images, you must create a registry instance. You can do this via the Azure Portal, the Azure CLI, or infrastructure-as-code tools like Terraform or Bicep. For this lesson, we will focus on the Azure CLI, as it is the most common tool for developers working with containerized workflows.
Step 1: Prerequisites
Ensure you have the Azure CLI installed and that you are logged in to your account. You will also need Docker installed on your local machine to build and test images.
Step 2: Create a Resource Group and Registry
A resource group is a logical container in Azure that holds related resources. We will create one first, followed by the registry.
# Create a resource group
az group create --name MyContainerGroup --location eastus
# Create the Azure Container Registry
az acr create --resource-group MyContainerGroup \
--name myuniqueacregistry \
--sku Basic
Note: The name of your registry must be globally unique within Azure, as it forms part of the URL (e.g., myuniqueacregistry.azurecr.io). The Basic SKU is perfect for learning and small projects, while Standard and Premium SKUs offer higher storage limits, geo-replication, and advanced networking features.
Step 3: Authenticating with the Registry
To push an image, your local Docker client must be authenticated with the registry. You can use your Azure CLI credentials to handle this automatically.
az acr login --name myuniqueacregistry
This command updates your local Docker configuration file, allowing you to interact with the registry as if it were a local service.
Working with Container Images
Once your registry is ready and you are authenticated, the workflow for managing images is identical to working with Docker Hub. The process involves tagging your local image and pushing it to the remote registry.
Tagging an Image
A Docker image tag consists of the registry URL, the repository name, and the version (or tag). If you don't include the registry URL, Docker assumes you are trying to push to Docker Hub.
# Example: Tagging an existing local image
docker tag my-app:v1 myuniqueacregistry.azurecr.io/my-app:v1
Pushing an Image
After tagging, you push the image to the remote registry. This uploads the image layers to your private Azure storage.
docker push myuniqueacregistry.azurecr.io/my-app:v1
Pulling an Image
When you need to deploy this image to a different environment, you pull it using the same naming convention.
docker pull myuniqueacregistry.azurecr.io/my-app:v1
Warning: Image Bloat A common mistake is pushing every single build to the registry without a cleanup strategy. Over time, your registry will become bloated with hundreds of unused or outdated images. This leads to increased storage costs and makes it difficult to manage your "source of truth." Always implement an image lifecycle policy to automatically delete old, unused tags.
Advanced Management: Retention and Lifecycle Policies
Managing a registry is not just about pushing images; it is about maintaining a healthy environment. Azure Container Registry provides "Lifecycle Policies" to automate the cleanup of images that are no longer needed.
Setting up a Retention Policy
You can define rules to automatically delete images that meet specific criteria, such as images that are older than 30 days or images that do not have a specific tag.
# Example: Create a policy to delete untagged images
az acr config retention update --registry myuniqueacregistry \
--type UntaggedManifests \
--status Enabled \
--days 7
This policy ensures that any image manifest that is not associated with a tag is automatically cleaned up after seven days. This is a critical best practice for keeping your storage costs predictable.
Security Best Practices
Security is the most important aspect of container management. Because your images contain your application code, they are a primary target for attackers.
1. Use Service Principals for CI/CD
Never use your personal Azure credentials in a CI/CD pipeline. Instead, create a "Service Principal"—an identity created specifically for your build server—and grant it AcrPush permissions.
# Create a service principal for the registry
az ad sp create-for-rbac --name my-ci-cd-sp \
--role AcrPush \
--scopes /subscriptions/<sub-id>/resourceGroups/MyContainerGroup/providers/Microsoft.ContainerRegistry/registries/myuniqueacregistry
2. Enable Vulnerability Scanning
If you are using the Basic or Standard tiers, ensure you are aware of your security posture. For Premium tiers, Azure provides integrated vulnerability scanning through Microsoft Defender for Cloud. This tool scans your images upon push and provides a report on known CVEs (Common Vulnerabilities and Exposures).
3. Content Trust
Content trust allows you to sign your images. When you push an image with content trust enabled, it is digitally signed. When you pull the image, the client verifies the signature. This prevents a scenario where an attacker might replace your image with a malicious version.
Comparing Registry Tiers
Choosing the right SKU for your registry depends on your scale, budget, and geographic requirements.
| Feature | Basic | Standard | Premium |
|---|---|---|---|
| Storage | 10 GB | 100 GB | 500 GB |
| Geo-replication | No | No | Yes |
| Content Trust | Yes | Yes | Yes |
| Webhooks | Yes | Yes | Yes |
| Private Link | No | No | Yes |
Note: If you are operating in a highly regulated environment that requires network isolation, you must use the Premium SKU to enable Azure Private Link. This allows your registry to be accessed over a private IP address within your Virtual Network, preventing any exposure to the public internet.
Integrating with CI/CD Pipelines
The true power of Azure Container Registry is realized when it is integrated into an automated CI/CD pipeline (such as GitHub Actions or Azure DevOps). In a professional workflow, a developer pushes code to a Git repository, which triggers a build process.
Example: GitHub Actions Workflow
In this scenario, GitHub Actions builds the Docker image and pushes it to ACR.
name: Build and Push to ACR
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Log in to ACR
uses: azure/docker-login@v1
with:
login-server: myuniqueacregistry.azurecr.io
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
- name: Build and push
run: |
docker build -t myuniqueacregistry.azurecr.io/my-app:${{ github.sha }} .
docker push myuniqueacregistry.azurecr.io/my-app:${{ github.sha }}
This workflow ensures that every commit to the main branch results in a uniquely tagged image in your registry. This makes it trivial to trace a production deployment back to the exact line of code that created it.
Common Pitfalls and How to Avoid Them
Even experienced engineers often encounter issues when working with container registries. Here are the most frequent mistakes and how to avoid them.
1. Using latest Tags in Production
A common mistake is tagging images as latest. While convenient for local development, it is dangerous in production. If you deploy an image tagged latest, your system may behave unpredictably because the "latest" version can change without your knowledge.
- The Fix: Always use semantic versioning (e.g.,
v1.0.1,v1.1.0) or the commit SHA as the tag. This ensures that your deployments are deterministic and repeatable.
2. Storing Secrets in Images
Never bake secrets (API keys, database passwords, or certificates) into your Docker images. Even though ACR is private, if your image is ever leaked or shared, those secrets will be compromised.
- The Fix: Use environment variables or Azure Key Vault to inject secrets into your containers at runtime. Your application should fetch these secrets only when the container starts.
3. Ignoring Network Latency
If your registry is in the East US region but your Kubernetes cluster is in West Europe, pulling images will be slow. This increases your deployment time and can lead to timeouts during scaling events.
- The Fix: Use the
PremiumSKU's geo-replication feature to keep images close to your compute resources. Alternatively, ensure your registry and compute resources are in the same Azure region.
4. Lack of Monitoring
Registries are often "set and forget" services. However, if you hit your storage limit, your builds will start failing.
- The Fix: Set up Azure Monitor alerts to notify you when your storage usage reaches 80% or 90%.
Deep Dive: How Geo-Replication Works
For organizations with a global footprint, downloading images from a single, distant registry is a major performance bottleneck. Azure Container Registry’s geo-replication feature solves this by creating a multi-master replication model.
When you enable geo-replication, ACR maintains a copy of your images in each selected region. When a deployment occurs in a specific region, the container orchestrator pulls the image from the local replica rather than traversing the global network. This results in faster startup times for your containers and better reliability.
Callout: The "Local-First" Strategy Geo-replication is not just for performance; it is also for disaster recovery. If a regional outage occurs in your primary registry location, your applications can still pull images from the replicas in other regions, ensuring your production environments remain operational.
Managing Access with RBAC
Azure Container Registry integrates seamlessly with Microsoft Entra ID (formerly Azure Active Directory). This means you don't need to manage separate usernames and passwords for your team members. You can assign roles to users or groups based on the principle of least privilege.
- AcrPull: Allows users or services to pull images. Use this for your production Kubernetes clusters.
- AcrPush: Allows users or services to push images. Use this for your CI/CD build agents.
- AcrDelete: Allows users to delete images. Use this sparingly, typically only for administrators.
- Owner: Grants full access, including the ability to manage permissions.
By assigning the AcrPull role to your AKS cluster’s managed identity, you eliminate the need for storing "image pull secrets" inside your Kubernetes clusters, which is a significant security improvement.
Troubleshooting Connectivity
Sometimes you might find that you cannot pull or push images despite having the right permissions. This is usually related to network configuration.
- Firewall Rules: If you have enabled "Firewall and Virtual Network" settings on your ACR, you must ensure that your local IP address or your VNet is on the allow-list.
- DNS Issues: Occasionally, Docker might have trouble resolving the registry URL. Ensure your local DNS settings are correct and that you can reach the endpoint via
nslookup myuniqueacregistry.azurecr.io. - Authentication Token Expiration: If you are using an automated process, the authentication token might have expired. Always use service principals with long-lived credentials or managed identities to avoid frequent manual re-authentication.
Best Practices for Image Layering
The way you structure your Dockerfile directly impacts how efficiently ACR stores and transfers your images. Docker uses "layers," and ACR is smart enough to only store unique layers.
- Order Matters: Place the commands that change the least (like installing system dependencies) at the top of your Dockerfile. Place commands that change frequently (like copying your source code) at the bottom.
- Use Small Base Images: Instead of using a full-blown OS image like
ubuntu, use lightweight alternatives likealpineordistroless. This reduces the size of your images, which speeds up both push/pull times and reduces the attack surface. - Multi-Stage Builds: Use multi-stage builds to separate your build environment from your runtime environment. You can compile your code in a heavy image and then copy only the final binary into a tiny, secure production image.
Example of a multi-stage Dockerfile:
# Build stage
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o out
# Runtime stage
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "my-app.dll"]
This approach ensures that your final image in ACR does not contain the source code or build tools, making it smaller and more secure.
Frequently Asked Questions (FAQ)
Q: Can I use Azure Container Registry with non-Azure platforms? A: Yes. Since ACR uses the standard Docker Registry API, you can use it with any container orchestrator or local machine that supports Docker, provided you have the correct credentials.
Q: Is ACR free?
A: There is a cost associated with the storage and data transfer of your registry. The Basic tier is very affordable, but you should check the current Azure pricing page for the most up-to-date information on storage rates and data egress fees.
Q: How do I move images from Docker Hub to ACR?
A: You can use the docker pull command to get the image from Docker Hub, then docker tag it for your ACR, and finally docker push it to your registry. For large migrations, consider using the acr import command, which allows you to move images directly between registries without needing to download them to your local machine.
Q: Can I host Helm charts in ACR? A: Yes, Azure Container Registry supports OCI (Open Container Initiative) artifacts, which includes Helm charts. This allows you to store your application code and your deployment templates in the same location.
Summary and Key Takeaways
Mastering Azure Container Registry is a fundamental skill for any cloud-native developer. It is not just a storage location for images; it is a critical component of your security, deployment, and operational strategy. By leveraging the features discussed in this lesson, you can ensure that your containerized applications are secure, performant, and reliable.
Key Takeaways:
- Centralized Hub: ACR acts as the single source of truth for your container images, integrating seamlessly with your CI/CD pipelines and Azure compute services.
- Security First: Always prioritize private access, use managed identities or service principals, and implement vulnerability scanning to protect your intellectual property.
- Lifecycle Management: Implement retention policies to prevent storage bloat and reduce costs. Automate the cleanup of untagged and old images.
- Deterministic Deployments: Move away from
latesttags. Use semantic versioning or commit SHAs to ensure that you know exactly what is running in your production environment. - Optimize for Performance: Use geo-replication to minimize latency for global deployments and optimize your Dockerfiles using multi-stage builds to keep image sizes small.
- Network Awareness: Understand the network requirements of your registry, especially if you are using private endpoints to isolate your registry from the public internet.
- Continuous Improvement: Regularly review your registry configuration as your project grows. What works for a small project may need to evolve into a more complex, geo-replicated, and highly secured setup as your application reaches a global audience.
By applying these principles, you will move from simply "using" a registry to "managing" a robust container delivery system that supports the long-term success of your software projects. Whether you are building a microservices architecture or a single containerized web app, the practices outlined here will provide a solid foundation for your cloud journey.
Reach the last section to complete this lesson and earn points — you're on section 1 of 12.
- Azure Container Registry Basics
- Azure Container Registry Basics Quiz5q
- Build and Store Container Images
- Build and Store Container Images Quiz5q
- ACR Tasks for Building Images
- ACR Tasks for Building Images Quiz5q
- Deploy to Azure App Service
- Deploy to Azure App Service Quiz5q
- Environment Variables and Secrets
- Environment Variables and Secrets Quiz5q
- Azure Container Apps Overview
- Azure Container Apps Overview Quiz5q
- Environment and Revision Management
- Environment and Revision Management Quiz5q
- KEDA Event-Driven Scaling
- KEDA Event-Driven Scaling Quiz5q
- Azure Kubernetes Service Basics
- Azure Kubernetes Service Basics Quiz5q
- AKS Manifest Files
- AKS Manifest Files Quiz5q
- Container Monitoring and Troubleshooting
- Container Monitoring and Troubleshooting Quiz5q
- Cosmos DB SDK Basics
- Cosmos DB SDK Basics Quiz5q
- Query Optimization
- Query Optimization Quiz5q
- Indexing Policies
- Indexing Policies Quiz5q
- Consistency Levels
- Consistency Levels Quiz5q
- Vector Similarity Search in Cosmos DB
- Vector Similarity Search in Cosmos DB Quiz5q
- Change Feed Processor
- Change Feed Processor Quiz5q
- PostgreSQL SDK Basics
- PostgreSQL SDK Basics Quiz5q
- Schema Design and Data Types
- Schema Design and Data Types Quiz5q
- PostgreSQL Indexing Strategies
- PostgreSQL Indexing Strategies Quiz5q
- pgvector for Vector Workloads
- pgvector for Vector Workloads Quiz5q
- Vector Similarity Search in PostgreSQL
- Vector Similarity Search in PostgreSQL Quiz5q
- RAG Patterns with PostgreSQL
- RAG Patterns with PostgreSQL Quiz5q
- OpenTelemetry SDK Basics
- OpenTelemetry SDK Basics Quiz5q
- Distributed Tracing
- Distributed Tracing Quiz5q
- KQL for Log Analytics
- KQL for Log Analytics Quiz5q
- Metrics Analysis
- Metrics Analysis Quiz5q
- Application Insights Integration
- Application Insights Integration Quiz5q
- Alerting and Diagnostics
- Alerting and Diagnostics Quiz5q
- Managed Identity Configuration
- Managed Identity Configuration Quiz5q
- Private Endpoints
- Private Endpoints Quiz5q
- Network Security Groups
- Network Security Groups Quiz5q
- Certificate Management
- Certificate Management Quiz5q
- RBAC for AI Services
- RBAC for AI Services Quiz5q
- Service Principal Authentication
- Service Principal Authentication Quiz5q
Enjoying the courses?
Everything stays free. Pro shows fewer ads, doubles the points you earn on every lesson and quiz so you progress twice as fast, unlocks half of every practice exam — plus full case studies — with the Learn & Exam study modes, and lets you read each lesson on one page.
- ✓ Fewer advertisements
- ✓ 2× points per lesson & quiz
- ✓ 50% of every exam unlocked
- ✓ Learn & Exam modes
- ✓ Distraction-free lessons