Docker in CI/CD Pipelines

Automate image building, vulnerability scanning, and Docker Hub / GitHub Container Registry publishing on every git commit.

1. Production GitHub Actions Workflow (`.github/workflows/deploy.yml`)

name: Build and Push Docker Image

on:
  push:
    branches: [ "main" ]

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Source Code
        uses: actions/checkout@v3

      - name: Set up Docker Buildx (For Caching & Multi-Arch)
        uses: docker/setup-buildx-action@v2

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and Push Image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: |${{ secrets.DOCKERHUB_USERNAME }}/myapp:latest
          cache-from: type=gha
          cache-to: type=gha,mode=max

Next Up

Learn Production Deployment: deploying containers to AWS ECS, DigitalOcean App Platform, and VPS servers with Nginx reverse proxy.

Next Lesson: Production Deployment →