Getting Started with Azure Container Services

Welcome to the Getting Started guide for Azure Container Services. This document will walk you through the initial steps to deploy and manage containerized applications on Microsoft Azure.

What are Containers?

Containers provide a lightweight, portable, and consistent way to package and run applications. They bundle an application's code, dependencies, and runtime into a single unit, ensuring it runs the same way regardless of the underlying environment. Azure offers a comprehensive suite of services to host, manage, and scale your containerized workloads.

Choosing the Right Azure Container Service

Azure offers several services tailored for containers. The most popular ones for orchestrating and running containers are:

Prerequisites

Before you begin, ensure you have the following:

Step 1: Create an Azure Container Registry (ACR)

An Azure Container Registry is a private Docker registry that you can use to store and manage your private Docker images and related artifacts. It's essential for pushing your container images to Azure.

You can create an ACR using the Azure CLI:


az acr create --resource-group myResourceGroup --name myACRRegistry --sku Basic
            

Replace myResourceGroup and myACRRegistry with your desired names.

Step 2: Build and Push a Docker Image

Assuming you have a Dockerfile for your application, build the image and push it to your ACR:

  1. Log in to your ACR:
    
    az acr login --name myACRRegistry
                        
  2. Build your Docker image:
    
    docker build -t myACRRegistry.azurecr.io/my-app:v1 .
                        
  3. Push the image to ACR:
    
    docker push myACRRegistry.azurecr.io/my-app:v1
                        

Step 3: Deploy to Azure Container Instances (ACI)

For a quick start, deploying to ACI is straightforward.

Create a container group with your pushed image:


az container create --resource-group myResourceGroup --name my-container --image myACRRegistry.azurecr.io/my-app:v1 --dns-name-label my-app-dns
            

This command will create a container group and assign it a DNS name label, making your container accessible via a public URL.

Step 4: Deploy to Azure Kubernetes Service (AKS)

For production workloads requiring orchestration, AKS is the recommended choice.

First, create an AKS cluster:


az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
            

Once the cluster is created, configure your Kubernetes context to connect to it:


az aks get-credentials --resource-group myResourceGroup --name myAKSCluster
            

Now you can deploy your application using Kubernetes manifests (YAML files). For example, a simple deployment:


apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      containers:
      - name: my-app
        image: myACRRegistry.azurecr.io/my-app:v1
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: LoadBalancer
            

Save this content as app.yaml and apply it:


kubectl apply -f app.yaml
            

Next Steps

Congratulations! You've taken your first steps with Azure Container Services. From here, you can explore: