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-actionto create a Buildx builder. - Log in to your registry (see the GHCR/Docker Hub guides).
- Run
docker/build-push-actionwithpush: trueandtags:.
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 }}:latestGotchas
- 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
How to Tag Images by Git SHA, Semver, and Branch in CIGenerate consistent image tags in GitHub Actions with docker/metadata-action, deriving tags from the git SHA,…
How to Push a Multi-Arch Image Manifest From CIBuild a multi-architecture image (amd64 and arm64) in GitHub Actions with QEMU, Buildx, and the platforms opt…