CI/CD Pipelines: Containers, Services, and Environments/Build and push Docker image with GitHub Actions

Authenticate, build, and push to a registry.

Section: Build and publish container images

Build and push Docker image with GitHub Actions

yaml
yaml
steps:
  - uses: actions/checkout@v4
  - uses: docker/login-action@v3
    with:
      registry: ghcr.io
      username: ${{ github.actor }}
      password: ${{ secrets.GITHUB_TOKEN }}
  - uses: docker/build-push-action@v6
    with:
      context: .
      push: true
      tags: ghcr.io/acme/myapp:${{ github.sha }}
Explanation

Combine checkout, registry login, and a build-push step for standard container release pipelines.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Build and publish container images
Build image in GitLab CI
Use Docker-in-Docker or a compatible runner setup.
OpenIn sheetyamlsame section
Deploy a new image to Kubernetes
Update a deployment image and monitor rollout status.
OpenIn sheetbashsame section
Start PostgreSQL service for tests
Run integration tests against a service container.
Use named environments
Attach production jobs to an environment with protection rules.
Run deploy only on deployment-capable agents
Target jobs to specific Jenkins workers or labels.