Deploy Docker on Azure with GitHub Actions

🐳 Docker 🔷 Microsoft Azure ⚙️ GitHub Actions

Configuration Files

Production-ready configuration files with detailed comments and best practices. Each file works together as a complete deployment solution.
name: Deploy to Azure Container Instances

on:
  push:
    branches: [main]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - uses: actions/checkout@v4

      - name: Log in to Container Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest

      - name: Azure Login
        uses: azure/login@v1
        with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}

      - name: Deploy to Azure Container Instances
        uses: azure/aci-deploy@v1
        with:
          resource-group: my-resource-group
          dns-name-label: my-app
          image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
          name: my-container
          location: eastus
          ports: 80 443
          cpu: 1
          memory: 1.5

Prerequisites

  • Azure account with active subscription
  • Azure CLI installed locally
  • Dockerfile in repository
  • GitHub repository

Deployment Steps

  • 1. Create Azure account
  • 2. Create resource group
  • 3. Create service principal: az ad sp create-for-rbac
  • 4. Add AZURE_CREDENTIALS to GitHub secrets
  • 5. Create Dockerfile
  • 6. Create workflow file
  • 7. Push to deploy
  • 8. Access at my-app.eastus.azurecontainer.io

Additional Notes

  • 🐳 Serverless containers
  • ⚡ Fast startup times
  • 💰 Pay per second
  • 🔧 ~$30-50/month for 1 vCPU, 1.5GB RAM
  • ⚠️ Not suitable for high-traffic apps (use AKS instead)