Skip to content
Latchkey

How to Build and Push an Image With Buildx in CI

docker/build-push-action builds with Buildx and pushes in a single step when push is true.

Set up Buildx with docker/setup-buildx-action, then run docker/build-push-action with push: true and one or more tags. Log in to the registry first.

Steps

  • Add docker/setup-buildx-action to create a Buildx builder.
  • Log in to your registry (see the GHCR/Docker Hub guides).
  • Run docker/build-push-action with push: true and tags:.

Workflow

.github/workflows/ci.yml
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:
      context: .
      push: true
      tags: ghcr.io/${{ github.repository }}:latest

Gotchas

  • Set push: ${{ github.event_name != 'pull_request' }} to skip pushing on PRs.
  • Buildx is required for multi-arch builds and registry cache exports.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →