Container Instances and Container Registries
Lab Objective
In this hands-on lab, you will learn how to:
- Create Azure Container Registry to store and manage container images securely
- Build container images directly in ACR using cloud-based build capabilities
- Configure registry authentication with admin credentials and managed identity
- Deploy containers to ACI from your private registry with various configurations
- Manage container lifecycle including scaling, restarting, and monitoring
- Implement container networking with virtual network integration and DNS resolution
- Monitor container performance using Azure Monitor and log analytics
Scenario: Your organization needs to containerize legacy applications and deploy them in a scalable, managed environment. Youβll use Azure Container Registry to build and store container images, then deploy them using Azure Container Instances for development, testing, and lightweight production workloads.
Please sign in to launch lab.
Pre-Provisioned Environment
Container Lab Environmentβββ Resource Group: ACR-ACI-Lab-RGβββ Azure Container Registry (acrlab[unique])β βββ SKU: Basicβ βββ Admin User: Enabledβ βββ Public Access: Enabledβ βββ Repository Webhooks: Ready for configurationβββ Virtual Network (container-vnet)β βββ Container Subnet (10.0.1.0/24)β βββ Management Subnet (10.0.2.0/24)βββ Log Analytics Workspace (container-logs[unique])β βββ Data Retention: 30 daysβ βββ Container Insights: Enabledβββ Application Insights (container-insights[unique])β βββ Container monitoring configuredβββ Storage Account (containerlogs[unique]) βββ Container: build-logs βββ Purpose: Store build artifacts and logsImportant: The Container Registry is pre-deployed and ready for building images. Youβll focus on image management, building, and container deployment workflows.
Lab Exercises
Part 1: Configure Container Registry Access
Step 1: Explore Container Registry Configuration
- Navigate to Resource Groups β
ACR-ACI-Lab-RG - Click on the Azure Container Registry
acrlab[unique] - Review the Overview section:
- Login server URL
- Current image count
- Storage usage
- Go to βAccess keysβ and note the admin credentials
Step 2: Test Registry Authentication
- Open Azure Cloud Shell (PowerShell)
- Run the following command to login to your registry:
Terminal window az acr login --name acrlab[unique] - Verify successful authentication
- List current repositories (should be empty initially):
Terminal window az acr repository list --name acrlab[unique]
Step 3: Configure Repository Permissions
- Go to βRepository permissionsβ in the registry
- Review the current access policies
- Note how admin access vs. managed identity access differs
- Check βNetworkingβ to see public access configuration
Expected Results: Container registry is accessible and ready for image operations with proper authentication configured.
Part 2: Build and Push Container Images
Step 1: Create Sample Application
- In Cloud Shell, create a new directory:
Terminal window mkdir webapp-democd webapp-demo - Create a simple Dockerfile:
Terminal window @"FROM nginx:alpineCOPY index.html /usr/share/nginx/html/EXPOSE 80"@ | Out-File -FilePath Dockerfile -Encoding ascii - Create a custom web page:
Terminal window @"<!DOCTYPE html><html><head><title>ACR Demo App</title></head><body style='font-family: Arial; text-align: center; padding: 50px;'><h1>Hello from Azure Container Registry!</h1><p>Container Instance: <span id='hostname'></span></p><script>document.getElementById('hostname').innerHTML = window.location.hostname;</script></body></html>"@ | Out-File -FilePath index.html -Encoding utf8
Step 2: Build Image Using ACR Tasks
- Build the image directly in Azure Container Registry:
Terminal window az acr build --registry acrlab[unique] --image webapp-demo:v1 . - Monitor the build progress in Cloud Shell
- Watch for successful completion message
- Verify the image was created:
Terminal window az acr repository show-tags --name acrlab[unique] --repository webapp-demo
Step 3: Build Variations and Tags
- Modify the index.html to show version 2:
Terminal window (Get-Content index.html) -replace 'Hello from Azure Container Registry!', 'Hello from ACR - Version 2!' | Set-Content index.html - Build version 2:
Terminal window az acr build --registry acrlab[unique] --image webapp-demo:v2 . - Tag the latest version:
Terminal window az acr build --registry acrlab[unique] --image webapp-demo:latest . - List all tags:
Terminal window az acr repository show-tags --name acrlab[unique] --repository webapp-demo
Expected Results: Multiple tagged versions of your web application are stored in the container registry and ready for deployment.
Part 3: Deploy Containers with Azure Container Instances
Step 1: Deploy First Container Instance
- Navigate to Home β Create a resource
- Search for βContainer Instancesβ and click βCreateβ
- Configure basic settings:
- Resource group:
ACR-ACI-Lab-RG - Container name:
webapp-demo-v1 - Region: East US
- Image source: Azure Container Registry
- Registry:
acrlab[unique] - Image:
webapp-demo - Image tag:
v1
- Resource group:
Step 2: Configure Container Network Settings
- Go to βNetworkingβ tab
- Configure networking:
- Networking type: Public
- DNS name label:
webapp-demo-v1-[unique] - Ports: 80 (TCP)
- Go to βAdvancedβ tab
- Set restart policy: βAlwaysβ
- Click βReview + createβ β Create
Step 3: Test Container Deployment
- Wait for deployment to complete
- Go to the Container Instance
webapp-demo-v1 - Copy the FQDN from the Overview
- Open browser and navigate to
http://[your-fqdn] - Verify the web application loads correctly
- Note the hostname displayed on the page
Expected Results: Container instance is running and serving the web application publicly with your custom content.
Part 4: Advanced Container Instance Configurations
Step 1: Deploy Multi-Container Group
- Create another container instance:
webapp-demo-v2 - Use the same configuration but:
- Image tag:
v2 - DNS name label:
webapp-demo-v2-[unique]
- Image tag:
- Deploy and test both versions side by side
- Compare the content differences
Step 2: Configure Environment Variables
- Go to Container Instance
webapp-demo-v1 - Click βContainersβ under Settings
- Click on the container name
- Add environment variables:
- Name:
APP_VERSION, Value:1.0 - Name:
ENVIRONMENT, Value:Development
- Name:
- Restart the container to apply changes
Step 3: Configure Resource Limits
- Edit the container configuration
- Set resource requests and limits:
- CPU: 0.5 cores
- Memory: 1 GB
- Save the configuration
- Monitor resource usage in the metrics section
Expected Results: Multiple container instances are running with different configurations, demonstrating various deployment scenarios.
Part 5: Container Networking and Security
Step 1: Deploy with Virtual Network Integration
- Create a new container instance:
webapp-secure - Configure with VNet integration:
- Networking type: Private
- Virtual network:
container-vnet - Subnet:
Container Subnet
- Deploy the container
Step 2: Test Private Networking
- Note that the private container has no public IP
- Create a simple test container with public access:
Terminal window az container create \--resource-group ACR-ACI-Lab-RG \--name test-client \--image mcr.microsoft.com/azure-cli \--restart-policy Never \--command-line "sleep 3600" - Connect to the test container and ping the private container
Step 3: Configure Container Registry Authentication
- Go to Container Instance settings
- Review how registry authentication is configured
- Note the use of managed identity vs admin credentials
- Test pulling images from the private registry
Expected Results: Containers are deployed in both public and private network configurations with secure registry access.
Part 6: Monitor and Manage Container Lifecycle
Step 1: Monitor Container Performance
- Go to any running container instance
- Click βMetricsβ under Monitoring
- Add metrics:
- CPU Usage
- Memory Usage
- Network In/Out
- Set time range to βLast hourβ
- Observe resource consumption patterns
Step 2: View Container Logs
- Go to βLogsβ under Monitoring
- Run this query to see container logs:
ContainerInstanceLog_CL| where ContainerGroup_s == "webapp-demo-v1"| order by TimeGenerated desc| take 50
- Review application and system logs
- Create a custom dashboard for monitoring
Step 3: Manage Container Lifecycle
- Test container restart functionality:
- Stop a running container
- Start it again
- Verify it maintains configuration
- Update container image:
- Change image tag to
latest - Apply the update
- Verify new version is running
- Change image tag to
- Scale container groups (if using container groups)
Expected Results: Complete visibility into container performance, logs, and lifecycle management capabilities.
Troubleshooting Guide
Container Registry Issues
- Build failures: Check Dockerfile syntax and base image availability
- Authentication errors: Verify ACR admin credentials or managed identity permissions
- Push/pull failures: Check network connectivity and registry public access settings
- Image not found: Verify repository name and tag spelling
Container Instance Issues
- Deployment failures: Check resource quotas and region availability
- Container wonβt start: Review container logs for application errors
- Network connectivity: Verify NSG rules and VNet configuration
- Resource constraints: Check CPU/memory limits and adjust as needed
Performance Issues
- Slow container startup: Optimize Dockerfile layers and base image size
- High resource usage: Review application code and resource allocations
- Network latency: Consider container placement and network topology
- Build time issues: Use multi-stage builds and layer caching
Key Takeaways
After completing this lab, you should understand:
- Azure Container Registry provides secure, private container image storage with cloud-based building capabilities
- ACR Tasks enable automated container builds without requiring local Docker installation
- Azure Container Instances offer serverless container hosting for development and lightweight production scenarios
- Container networking can be configured for both public internet access and private VNet integration
- Registry authentication supports both admin credentials and managed identity for secure access
- Container monitoring provides insights into performance, logs, and resource utilization
Decision Matrix: When to Use ACR and ACI
| Scenario | ACR + ACI | ACR + AKS | ACR + App Service | Local Development |
|---|---|---|---|---|
| Development/Testing | β Recommended | β οΈ Complex setup | β Good option | β Simple |
| Lightweight production | β Recommended | β Overkill | β Good option | β Not scalable |
| Microservices architecture | β οΈ Limited orchestration | β Recommended | β οΈ Service complexity | β Not suitable |
| Batch processing | β Recommended | β οΈ May be overkill | β Not suitable | β Limited resources |
| Enterprise applications | β Limited features | β Recommended | β Good option | β Not production-ready |
| CI/CD integration | β Good | β Excellent | β Good | β Limited |
Key Decision Factors:
- Orchestration needs: Use AKS for complex container orchestration
- Scaling requirements: ACI provides basic scaling, AKS offers advanced scaling
- Cost considerations: ACI is pay-per-use, AKS has baseline costs
- Management complexity: ACI is simpler, AKS requires more operational knowledge
Cleanup Instructions
- Navigate to Resource Groups in Azure portal
- Click on βACR-ACI-Lab-RGβ
- Click βDelete resource groupβ
- Type the resource group name to confirm
- Click βDeleteβ
Estimated cleanup time: 5-10 minutes