docker/build-push-action@v7

Build and push Docker images with Buildx

At a glance

Latest major
v7
Repository
docker/build-push-action
Inputs
33 (0 required)
Outputs
3
Runs using
node24
License
Apache-2.0
Last checked

Inputs and outputs come straight from the action's official action.yml. See our editorial standards.

Usage

- uses: docker/build-push-action@v7

Inputs

NameRequiredDefaultDescription
add-hostsNononeList of a customs host-to-IP mapping (e.g., docker:10.180.0.1)
allowNononeList of extra privileged entitlement (e.g., network.host,security.insecure)
annotationsNononeList of annotation to set to the image
attestsNononeList of attestation parameters (e.g., type=sbom,generator=image)
build-argsNononeList of build-time variables
build-contextsNononeList of additional build contexts (e.g., name=path)
builderNononeBuilder instance
cache-fromNononeList of external cache sources for buildx (e.g., user/app:cache, type=local,src=path/to/dir)
cache-toNononeList of cache export destinations for buildx (e.g., user/app:cache, type=local,dest=path/to/dir)
callNononeSet method for evaluating build (e.g., check)
cgroup-parentNononeOptional parent cgroup for the container used in the build
contextNononeBuild's context is the set of files located in the specified PATH or URL
fileNononePath to the Dockerfile
labelsNononeList of metadata for an image
loadNofalseLoad is a shorthand for --output=type=docker
networkNononeSet the networking mode for the RUN instructions during build
no-cacheNofalseDo not use cache when building the image
no-cache-filtersNononeDo not cache specified stages
outputsNononeList of output destinations (format: type=local,dest=path)
platformsNononeList of target platforms for build
provenanceNononeGenerate provenance attestation for the build (shorthand for --attest=type=provenance)
pullNofalseAlways attempt to pull all referenced images
pushNofalsePush is a shorthand for --output=type=registry
sbomNononeGenerate SBOM attestation for the build (shorthand for --attest=type=sbom)
secretsNononeList of secrets to expose to the build (e.g., key=string, GIT_AUTH_TOKEN=mytoken)
secret-envsNononeList of secret env vars to expose to the build (e.g., key=envname, MY_SECRET=MY_ENV_VAR)
secret-filesNononeList of secret files to expose to the build (e.g., key=filename, MY_SECRET=./secret.txt)
shm-sizeNononeSize of /dev/shm (e.g., 2g)
sshNononeList of SSH agent socket or keys to expose to the build
tagsNononeList of tags
targetNononeSets the target stage to build
ulimitNononeUlimit options (e.g., nofile=1024:1024)
github-tokenNo${{ github.token }}GitHub Token used to authenticate against a repository for Git context

Outputs

NameDescription
imageidImage ID
digestImage digest
metadataBuild result metadata

Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.

Examples

Build an image without pushing

Check that the Dockerfile builds on every pull request.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Build and push Docker images
        uses: docker/build-push-action@v7
        with:
          context: .
          push: false
          tags: "my-app:ci"

Build and push to GHCR with layer cache

Reuse layers through the GitHub Actions cache backend.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read
  packages: write

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: docker/setup-buildx-action@v4
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push Docker images
        uses: docker/build-push-action@v7
        with:
          context: .
          push: true
          tags: "ghcr.io/${{ github.repository }}:latest"
          cache-from: type=gha
          cache-to: type=gha,mode=max

Each example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.

Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.