Interview Prep/Docker/CI/CD and production rollouts

Design a GitHub Actions workflow that builds, scans and pushes an image.

IntermediateScenarioCI/CD and production rollouts
Answer

Situation read → Standard CI for containers.

What I'd do →

steps:
  - uses: actions/checkout@v4
  - uses: docker/setup-buildx-action@v3
  - uses: docker/login-action@v3
    with: { registry: ghcr.io, username: ${{ github.actor }}, password: ${{ secrets.GITHUB_TOKEN }} }
  - uses: docker/build-push-action@v6
    with:
      push: false
      load: true
      tags: ghcr.io/acme/app:${{ github.sha }}
      cache-from: type=gha
      cache-to: type=gha,mode=max
  - run: trivy image --exit-code 1 --severity CRITICAL ghcr.io/acme/app:${{ github.sha }}
  - run: docker push ghcr.io/acme/app:${{ github.sha }}

Why → Scan before push so bad images never reach the registry.

Interview tip → Pin actions by SHA in sensitive repos.

All Docker questions Roadmap: Docker & containers

More on CI/CD and production rollouts