DEV Community

Abhay Singh Kathayat
Abhay Singh Kathayat

Posted on

Docker in Microsoft Azure: Running Containers with AKS, ACI, and ACR

Docker in Microsoft Azure (Azure Kubernetes Service)

Microsoft Azure offers robust solutions for running Docker containers and managing containerized applications, with Azure Kubernetes Service (AKS) being one of the primary services for orchestrating Docker containers in a scalable and managed environment. Azure provides seamless integration between Docker, Azure services, and Kubernetes for managing containerized workloads.


1. Docker with Azure Kubernetes Service (AKS)

Overview

Azure Kubernetes Service (AKS) is a fully managed Kubernetes service that simplifies the deployment, management, and scaling of containerized applications using Docker containers. AKS takes care of the underlying Kubernetes infrastructure, providing features like automated updates, scaling, monitoring, and more.

Key Features of AKS

  • Fully Managed Kubernetes: Azure handles Kubernetes cluster management, allowing developers to focus on building and deploying applications.
  • Integrated with Azure Services: AKS integrates with Azure Active Directory, Azure Monitor, and Azure DevOps.
  • Autoscaling: AKS supports horizontal scaling for your application based on load and traffic.
  • Secure and Reliable: AKS ensures the secure management of applications with built-in security features like Azure Key Vault and automated patching.

Steps to Deploy Docker Containers on AKS

  1. Create a Resource Group:
   az group create --name myResourceGroup --location eastus
Enter fullscreen mode Exit fullscreen mode
  1. Create an AKS Cluster:
   az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 3 --enable-addons monitoring --generate-ssh-keys
Enter fullscreen mode Exit fullscreen mode
  1. Get AKS Credentials (to configure kubectl to access the cluster):
   az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
Enter fullscreen mode Exit fullscreen mode
  1. Create Docker Image: Build your Docker image and push it to a container registry like Azure Container Registry (ACR) or Docker Hub:
   docker build -t myacr.azurecr.io/my-app .
   docker push myacr.azurecr.io/my-app
Enter fullscreen mode Exit fullscreen mode
  1. Create Kubernetes Deployment: Deploy the Docker image in your Kubernetes cluster by creating a deployment.yaml file:
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: my-app
   spec:
     replicas: 3
     selector:
       matchLabels:
         app: my-app
     template:
       metadata:
         labels:
           app: my-app
       spec:
         containers:
           - name: my-container
             image: myacr.azurecr.io/my-app
             ports:
               - containerPort: 80
Enter fullscreen mode Exit fullscreen mode
  1. Apply the Deployment:
   kubectl apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Expose the Application: To expose the service publicly, create a LoadBalancer service:
   kubectl expose deployment my-app --type=LoadBalancer --name=my-app-service
Enter fullscreen mode Exit fullscreen mode
  1. Access the Application: Use the external IP address provided by the LoadBalancer service to access your deployed application.

Use Case

AKS is perfect for large-scale containerized applications that require Kubernetes orchestration. It works well for microservices, machine learning models, and web applications that need to scale dynamically.


2. Docker with Azure Container Instances (ACI)

Overview

Azure Container Instances (ACI) is a service for running containers without managing the underlying infrastructure. ACI provides a simpler, more cost-effective solution for running isolated containers compared to AKS, but it lacks the full orchestration capabilities of Kubernetes.

Key Features of ACI

  • Instant Container Deployment: Spin up containers within seconds without needing to manage VMs.
  • Single-Container Support: Ideal for running single containers or stateless applications.
  • Integrated with Azure Services: ACI integrates seamlessly with other Azure services like Azure Virtual Network, Azure Storage, and Azure Monitoring.

Steps to Run Docker Containers on ACI

  1. Create an Azure Container Instance:
   az container create --name my-container --image myacr.azurecr.io/my-app --resource-group myResourceGroup --cpu 1 --memory 1.5 --port 80
Enter fullscreen mode Exit fullscreen mode
  1. Access the Application: After the container instance is created, Azure will provide an external IP address to access your application.

Use Case

ACI is ideal for quick, lightweight container workloads like testing, small services, or isolated jobs that do not need orchestration.


3. Docker with Azure Container Registry (ACR)

Overview

Azure Container Registry (ACR) is a private Docker registry for storing and managing your Docker images. ACR integrates with other Azure services and provides enhanced security and monitoring features.

Key Features of ACR

  • Private Registry: Store and manage Docker images securely.
  • Integrated with AKS: Easily integrate with AKS to deploy containers stored in your registry.
  • Geo-Replication: Distribute your Docker images across multiple regions for higher availability.

Steps to Use Azure Container Registry

  1. Create an ACR Registry:
   az acr create --resource-group myResourceGroup --name myacr --sku Basic
Enter fullscreen mode Exit fullscreen mode
  1. Login to ACR:
   az acr login --name myacr
Enter fullscreen mode Exit fullscreen mode
  1. Tag and Push Docker Images to ACR:
   docker tag my-app myacr.azurecr.io/my-app
   docker push myacr.azurecr.io/my-app
Enter fullscreen mode Exit fullscreen mode
  1. Pull Images from ACR in AKS:
   kubectl create secret docker-registry acr-secret --docker-server=myacr.azurecr.io --docker-username=myacr --docker-password=mypassword --docker-email=myemail@example.com
Enter fullscreen mode Exit fullscreen mode

Comparison of AKS, ACI, and ACR

Feature Azure Kubernetes Service (AKS) Azure Container Instances (ACI) Azure Container Registry (ACR)
Use Case Large-scale container orchestration Simple, single-container workloads Storing Docker images securely
Scaling Auto-scaling (horizontal) No scaling (fixed resources) N/A
Management Fully managed Kubernetes Managed containers without VM setup Managed private container registry
Deployment Speed Moderate Fast (within seconds) N/A

4. Docker in Azure DevOps

Azure DevOps provides a set of services for managing the entire lifecycle of containerized applications. By integrating Docker with Azure Pipelines, developers can automate their CI/CD workflows to build, test, and deploy Docker containers to Azure.

Key Features

  • CI/CD Pipelines: Automate the build and deployment of Docker containers.
  • Build and Push: Automatically build Docker images and push them to ACR or Docker Hub.
  • Integrated with AKS and ACI: Deploy Docker containers directly to AKS or ACI.

Steps to Use Docker in Azure DevOps

  1. Create a Dockerfile for your application.
  2. Create an Azure Pipeline to automate Docker image builds.
  3. Configure Deployment to AKS or ACI from the pipeline.

Conclusion

Docker in Microsoft Azure provides several robust solutions for running, managing, and scaling containerized applications:

  • Azure Kubernetes Service (AKS) is ideal for orchestrating complex containerized applications that require scalability and high availability.
  • Azure Container Instances (ACI) is perfect for simpler, lightweight applications that don’t require orchestration.
  • Azure Container Registry (ACR) is a secure and scalable registry for storing and managing Docker images.

These services, combined with Azure’s cloud-native tools, enable developers to easily deploy and scale Docker containers in a secure and efficient manner.

Follow me on Twitter for more updates on Docker and Azure! 🚀


Top comments (0)