End-to-End Guide: Build, Push & Deploy a Docker App on Azure (ACR + AKS)

 

This blog walks you through a complete DevOps workflow:

  • Login to Azure
  • Create Azure Container Registry (ACR)
  • Build & push a Docker image
  • Deploy it to Azure Kubernetes Service (AKS)

We’ll use a simple web server app instead of Python.


🧭 Architecture Overview

Local (azure-client)

Docker Build

Azure Container Registry (ACR)

Azure Kubernetes Service (AKS)

Public Web App (via Service)

πŸ” Step 1: Login to Azure

Using Azure CLI

az login

If multiple subscriptions:

az account set --subscription "Your-Subscription-Name"

Using Azure Portal

  1. Go to https://portal.azure.com
  2. Search → Resource Groups
  3. Select your resource group (example):

    demo-rg-devops

πŸ“¦ Step 2: Create Azure Container Registry (ACR)

Option 1: Azure CLI

az acr create \
--resource-group demo-rg-devops \
--name devopsregistry01 \
--sku Basic \
--location eastus

Option 2: Azure Portal

  1. Search → Container Registries
  2. Click Create
  3. Fill:
    • Registry Name: devopsregistry01
    • Region: East US
    • Pricing Tier: Basic
  4. Click Review + Create

πŸ” Step 3: Login to ACR

az acr login --name devopsregistry01

🌐 Step 4: Create Simple Web App (Docker)

Move to your working directory:

cd /root/webapp

πŸ“„ Create index.html

<h1>Welcome to DevOps Demo App πŸš€</h1>
<p>Deployed using ACR & AKS</p>

πŸ“„ Create Dockerfile

# Simple Nginx Web Server
FROM nginx:alpine

COPY index.html /usr/share/nginx/html/index.html

EXPOSE 80

🐳 Step 5: Build Docker Image

docker build -t devopsregistry01:latest .

🏷️ Step 6: Tag Image for ACR

docker tag devopsregistry01:latest devopsregistry01.azurecr.io/devops-webapp:latest

πŸ“€ Step 7: Push Image to ACR

docker push devopsregistry01.azurecr.io/devops-webapp:latest

☸️ Step 8: Create AKS Cluster

az aks create \
--resource-group demo-rg-devops \
--name devops-aks-cluster \
--node-count 1 \
--enable-addons monitoring \
--generate-ssh-keys \
--attach-acr devopsregistry01

πŸ”‘ Step 9: Connect to AKS

az aks get-credentials \
--resource-group demo-rg-devops \
--name devops-aks-cluster

Verify:

kubectl get nodes

πŸš€ Step 10: Deploy Application to Kubernetes

πŸ“„ Create Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
spec:
replicas: 2
selector:
matchLabels:
app: webapp
template:
metadata:
labels:
app: webapp
spec:
containers:
- name: webapp
image: devopsregistry01.azurecr.io/devops-webapp:latest
ports:
- containerPort: 80

Apply:

kubectl apply -f deployment.yaml

πŸ“„ Create Service

apiVersion: v1
kind: Service
metadata:
name: webapp-service
spec:
type: LoadBalancer
selector:
app: webapp
ports:
- port: 80
targetPort: 80

Apply:

kubectl apply -f service.yaml

🌍 Step 11: Access the Application

Get external IP:

kubectl get svc webapp-service

Example output:

EXTERNAL-IP: 20.xx.xx.xx

Open in browser:

http://<EXTERNAL-IP>

πŸŽ‰ You should see:

Welcome to DevOps Demo App πŸš€
Deployed using ACR & AKS

πŸ“Š Final Summary

ComponentName
Resource Groupdemo-rg-devops
ACRdevopsregistry01
Imagedevops-webapp:latest
AKS Clusterdevops-aks-cluster
Deploymentwebapp-deployment
Servicewebapp-service

⚠️ Common Issues & Fixes

❌ Image Pull Error

kubectl describe pod <pod-name>

✔ Fix: Ensure ACR is attached to AKS


❌ External IP Pending

✔ Wait 2–5 minutes (Azure LoadBalancer provisioning)


❌ Push Failed

✔ Ensure:

az acr login --name devopsregistry01

πŸ’‘ Pro Tips

  • Use az acr build to skip local Docker
  • Enable autoscaling in AKS for production
  • Use Helm charts for better deployments
  • Integrate CI/CD (Azure DevOps / GitHub Actions)

🎯 Conclusion

You’ve successfully:

  • Built a Docker image
  • Stored it in ACR
  • Deployed it to AKS
  • Exposed it to the internet

This is the core DevOps pipeline used in real-world production environments.

No comments:

Post a Comment