Skip to content
Latchkey

docker/build-push-action

Build and push a Docker image using Buildx, with cache and multi-platform support.

Official actionCategory: Docker & ContainersLatest v6View on GitHub

What it does

docker/build-push-action wraps docker buildx build for CI. It builds from a Dockerfile and can push to any registry, emit an image digest, and cache layers between runs.

It is almost always used after docker/setup-buildx-action (and docker/login-action to push), with docker/metadata-action supplying the tags and labels.

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: docker/setup-buildx-action@v3
  - uses: docker/login-action@v3
    with:
      username: ${{ secrets.DOCKERHUB_USERNAME }}
      password: ${{ secrets.DOCKERHUB_TOKEN }}
  - uses: docker/build-push-action@v6
    with:
      push: true
      tags: myorg/app:latest
      cache-from: type=gha
      cache-to: type=gha,mode=max

Inputs

InputDescriptionDefaultRequired
contextBuild context path or URL.git contextNo
filePath to the Dockerfile.DockerfileNo
pushPush the image to the registry after building.falseNo
tagsComma or newline separated list of image tags.-No
platformsTarget platforms, e.g. linux/amd64,linux/arm64.hostNo
cache-fromExternal cache source, e.g. type=gha.-No
cache-toCache export destination, e.g. type=gha,mode=max.-No
build-argsBuild-time variables passed to the Dockerfile.-No

Outputs

OutputDescription
imageidThe built image ID.
digestThe image digest after push.
metadataBuild result metadata (JSON).

Notes

Use cache-from: type=gha and cache-to: type=gha,mode=max to reuse layers across runs via the GitHub Actions cache.

Multi-platform builds require docker/setup-qemu-action for the non-native architecture.

Common errors

  • buildx: command not found or a Buildx driver error means docker/setup-buildx-action did not run first. Add it before this step.
  • denied: requested access to the resource is denied on push means docker/login-action did not authenticate, or the token lacks push scope.
  • A slow build that never reuses layers usually has no cache-from/cache-to configured.

Security and pinning

  • Pin build-push-action to a commit SHA.
  • Pass registry credentials from secrets via docker/login-action; never bake them into the image or build-args (build args are visible in the image history).

Alternatives and related

Frequently asked questions

How do I cache Docker layers in GitHub Actions?
Set cache-from: type=gha and cache-to: type=gha,mode=max. This stores layers in the Actions cache and reuses them on later runs.
How do I build for arm64 and amd64?
Add docker/setup-qemu-action, then set platforms: linux/amd64,linux/arm64 on build-push-action.
Running docker/build-push-action? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card