Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Build and push Docker images

Actions
Build and push Docker images with Buildx
v6.18.0
Latest
Verified creator
Star (5K)

Verified

GitHub has manually verified the creator of the action as an official partner organization. For more info seeAbout badges in GitHub Marketplace.

GitHub releaseGitHub marketplaceCI workflowTest workflowCodecov

About

GitHub Action to build and push Docker images withBuildxwith full support of the features provided byMoby BuildKitbuilder toolkit. This includes multi-platform build, secrets, remote cache, etc.and different builder deployment/namespacing options.

Screenshot


Usage

In the examples below we are also using 3 other actions:

  • setup-buildx action willcreate and boot a builder using by default thedocker-container driver.This isnot required but recommended using it to be able to buildmulti-platform images, export cache, etc.
  • setup-qemu action can beuseful if you want to add emulation support with QEMU to be able to buildagainst more platforms.
  • login action will take care tolog in against a Docker registry.

Git context

By default, this action uses theGit context,so you don't need to use theactions/checkoutaction to check out the repository as this will be done directly byBuildKit.

The git reference will be based on theevent that triggered your workflowand will result in the following context:https://github.com/<owner>/<repo>.git#<ref>.

name:cion:push:jobs:docker:runs-on:ubuntu-lateststeps:      -name:Login to Docker Hubuses:docker/login-action@v3with:username:${{ vars.DOCKERHUB_USERNAME }}password:${{ secrets.DOCKERHUB_TOKEN }}      -name:Set up QEMUuses:docker/setup-qemu-action@v3      -name:Set up Docker Buildxuses:docker/setup-buildx-action@v3      -name:Build and pushuses:docker/build-push-action@v6with:push:truetags:user/app:latest

Be careful becauseany file mutation in the steps that precede the build stepwill be ignored, including processing of the.dockerignore file sincethe context is based on the Git reference. However, you can use thePath context using thecontext input alongsidetheactions/checkout action to removethis restriction.

Default Git context can also be provided using theHandlebars templateexpression{{defaultContext}}. Here we can use it to provide a subdirectoryto the default Git context:

      -name:Build and pushuses:docker/build-push-action@v6with:context:"{{defaultContext}}:mysubdir"push:truetags:user/app:latest

Building from the current repository automatically uses theGitHub Token,so it does not need to be passed. If you want to authenticate against anotherprivate repository, you have to use asecretnamedGIT_AUTH_TOKEN to be able to authenticate against it with Buildx:

      -name:Build and pushuses:docker/build-push-action@v6with:push:truetags:user/app:latestsecrets:|            GIT_AUTH_TOKEN=${{ secrets.MYTOKEN }}

Path context

name:cion:push:jobs:docker:runs-on:ubuntu-lateststeps:      -name:Checkoutuses:actions/checkout@v5      -name:Login to Docker Hubuses:docker/login-action@v3with:username:${{ vars.DOCKERHUB_USERNAME }}password:${{ secrets.DOCKERHUB_TOKEN }}      -name:Set up QEMUuses:docker/setup-qemu-action@v3      -name:Set up Docker Buildxuses:docker/setup-buildx-action@v3      -name:Build and pushuses:docker/build-push-action@v6with:context:.push:truetags:user/app:latest

Examples

Summaries

This action generates ajob summarythat provides a detailed overview of the build execution. The summary shows anoverview of all the steps executed during the build, including the build inputsand eventual errors.

build-push-action job summary

The summary also includes a link for downloading the build record withadditional details about the build, including build stats, logs, outputs, andmore. The build record can be imported to Docker Desktop for inspecting thebuild in greater detail.

Warning

If you're using theactions/download-artifactaction in your workflow, you need to ignore the build record artifactsifname andpattern inputs are not specified (defaults to download all artifacts of the workflow),otherwise the action will fail:

-uses:actions/download-artifact@v4with:pattern:"!*.dockerbuild"

More info:actions/toolkit#1874

Summaries are enabled by default, but can be disabled with theDOCKER_BUILD_SUMMARYenvironment variable.

For more information about summaries, refer to thedocumentation.

Customizing

inputs

The following inputs can be used asstep.with keys:

List type is a newline-delimited string

cache-from:|  user/app:cache  type=local,src=path/to/dir

CSV type is a comma-delimited string

tags:name/app:latest,name/app:1.0.0
NameTypeDescription
add-hostsList/CSVList ofcustoms host-to-IP mapping (e.g.,docker:10.180.0.1)
allowList/CSVList ofextra privileged entitlement (e.g.,network.host,security.insecure)
annotationsListList of annotation to set to the image
attestsListList ofattestation parameters (e.g.,type=sbom,generator=image)
builderStringBuilder instance (seesetup-buildx action)
build-argsListList ofbuild-time variables
build-contextsListList of additionalbuild contexts (e.g.,name=path)
cache-fromListList ofexternal cache sources (e.g.,type=local,src=path/to/dir)
cache-toListList ofcache export destinations (e.g.,type=local,dest=path/to/dir)
callStringSetmethod for evaluating build (e.g.,check)
cgroup-parentStringOptionalparent cgroup for the container used in the build
contextStringBuild's context is the set of files located in the specifiedPATH orURL (defaultGit context)
fileStringPath to the Dockerfile. (default{context}/Dockerfile)
labelsListList of metadata for an image
loadBoolLoad is a shorthand for--output=type=docker (defaultfalse)
networkStringSet the networking mode for theRUN instructions during build
no-cacheBoolDo not use cache when building the image (defaultfalse)
no-cache-filtersList/CSVDo not cache specified stages
outputsListList ofoutput destinations (format:type=local,dest=path)
platformsList/CSVList oftarget platforms for build
provenanceBool/StringGenerateprovenance attestation for the build (shorthand for--attest=type=provenance)
pullBoolAlways attempt to pull all referenced images (defaultfalse)
pushBoolPush is a shorthand for--output=type=registry (defaultfalse)
sbomBool/StringGenerateSBOM attestation for the build (shorthand for--attest=type=sbom)
secretsListList ofsecrets to expose to the build (e.g.,key=string,GIT_AUTH_TOKEN=mytoken)
secret-envsList/CSVList ofsecret env vars to expose to the build (e.g.,key=envname,MY_SECRET=MY_ENV_VAR)
secret-filesListList ofsecret files to expose to the build (e.g.,key=filename,MY_SECRET=./secret.txt)
shm-sizeStringSize of/dev/shm (e.g.,2g)
sshListList ofSSH agent socket or keys to expose to the build
tagsList/CSVList of tags
targetStringSets the target stage to build
ulimitListUlimit options (e.g.,nofile=1024:1024)
github-tokenStringGitHub Token used to authenticate against a repository forGit context (default${{ github.token }})

outputs

The following outputs are available:

NameTypeDescription
imageidStringImage ID
digestStringImage digest
metadataJSONBuild result metadata

environment variables

NameTypeDefaultDescription
DOCKER_BUILD_CHECKS_ANNOTATIONSBooltrueIffalse, GitHub annotations are not generated forbuild checks
DOCKER_BUILD_SUMMARYBooltrueIffalse,build summary generation is disabled
DOCKER_BUILD_RECORD_UPLOADBooltrueIffalse, build record upload asGitHub artifact is disabled
DOCKER_BUILD_RECORD_RETENTION_DAYSNumberDuration after which build record artifact will expire in days. Defaults to repository/orgretention settings if unset or0
DOCKER_BUILD_EXPORT_LEGACYBoolfalseIftrue, exports build using legacy export-build tool instead ofbuildx history export command

Troubleshooting

SeeTROUBLESHOOTING.md

Contributing

Want to contribute? Awesome! You can find information about contributing tothis project in theCONTRIBUTING.md

Build and push Docker images is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Build and push Docker images with Buildx
v6.18.0
Latest

Verified

GitHub has manually verified the creator of the action as an official partner organization. For more info seeAbout badges in GitHub Marketplace.

Build and push Docker images is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.


[8]ページ先頭

©2009-2025 Movatter.jp