Hands-on LabLesson 14 of 16

🚀 Lab: Push Image to Registry and Deploy

Push your Docker image to Azure Container Registry, pull it on another machine, and simulate a full deployment workflow with versioned tags.

🎯
Lab Objectives

Authenticate to ACR, tag your image correctly, push it, verify it appears in ACR, pull it back, and run it — simulating the CI/CD promotion workflow used in production.

📋 Prerequisites

🔧 Step 1 — Create Azure Container Registry

bash
# Login to Azure az login # Create a resource group (skip if you have one) az group create --name docker-lab-rg --location eastus # Create ACR (must be globally unique name) az acr create \ --resource-group docker-lab-rg \ --name myacrdockerlab \ # change this to your unique name --sku Basic \ --admin-enabled true # Get the login server URL az acr show --name myacrdockerlab --query loginServer --output tsv # Output: myacrdockerlab.azurecr.io

🔧 Step 2 — Authenticate and Tag

bash
# Login to ACR (uses Azure credentials) az acr login --name myacrdockerlab # Tag your image with the full ACR path docker tag mywebapp:1.0 myacrdockerlab.azurecr.io/mywebapp:1.0 docker tag mywebapp:1.0 myacrdockerlab.azurecr.io/mywebapp:latest # Verify tags docker image ls myacrdockerlab.azurecr.io/mywebapp

🔧 Step 3 — Push to ACR

bash
# Push both tags docker push myacrdockerlab.azurecr.io/mywebapp:1.0 docker push myacrdockerlab.azurecr.io/mywebapp:latest # Verify in ACR az acr repository list --name myacrdockerlab --output table # See all tags for the repository az acr repository show-tags \ --name myacrdockerlab \ --repository mywebapp \ --output table

🔧 Step 4 — Simulate Deployment (Pull and Run)

bash
# Delete local image to simulate a fresh machine docker rmi mywebapp:1.0 docker rmi myacrdockerlab.azurecr.io/mywebapp:1.0 # Pull from ACR (simulates what AKS/server does) docker pull myacrdockerlab.azurecr.io/mywebapp:1.0 # Run the pulled image docker run -d \ --name prod-webapp \ -p 8080:3000 \ --memory 256m \ myacrdockerlab.azurecr.io/mywebapp:1.0 # Verify curl http://localhost:8080

🔧 Step 5 — Rolling Update Simulation

bash
# Simulate a code change — update the message in server.js # Then rebuild with new version tag docker build -t myacrdockerlab.azurecr.io/mywebapp:1.1 . docker push myacrdockerlab.azurecr.io/mywebapp:1.1 # Deploy new version (stop old, run new) docker stop prod-webapp docker rm prod-webapp docker run -d \ --name prod-webapp \ -p 8080:3000 \ myacrdockerlab.azurecr.io/mywebapp:1.1 # Verify new version running curl http://localhost:8080 # Rollback if needed docker stop prod-webapp docker rm prod-webapp docker run -d --name prod-webapp -p 8080:3000 \ myacrdockerlab.azurecr.io/mywebapp:1.0

🔧 Step 6 — Cleanup Azure Resources

bash
# Remove ACR (stops billing) az acr delete --name myacrdockerlab --resource-group docker-lab-rg --yes # Or remove the whole resource group az group delete --name docker-lab-rg --yes --no-wait
⚠️
Clean up Azure resources

ACR Basic tier costs approximately $0.167/day even when idle. Always delete lab resources after use to avoid unexpected charges.

✅ Lab Completion Checklist