This document explains how to leverage Docker Buildx in the context of the Docker Build-Push Action project (https://github.com/docker/build-push-action/). We will cover the benefits of using Buildx, its configuration options, and how it facilitates multi-platform builds.
What is Docker Buildx?
Docker Buildx is a tool that allows you to build multi-platform Docker images more efficiently. It uses the Moby BuildKit backend and provides a unified API for build pipelines with consistent configuration and execution.
Benefits of using Buildx
- Multi-platform image building: Buildx enables you to build images for multiple platforms (e.g., Linux, Windows, ARM) in a single command.
- Improved performance: Buildx leverages the power of distributed builds, allowing you to distribute the build load across multiple machines.
- Consistent configuration: Buildx provides a unified API for build pipelines, ensuring consistent configuration and execution.
Configuring Buildx in GitHub Actions
To use Buildx in GitHub Actions, you can utilize the docker/setup-buildx-action
action. This action sets up Buildx on the GitHub Actions runner and optionally configures it with a specific version or BuildKit image.
Basic Configuration
To configure Buildx with the default settings, use the following code snippet:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Version Pinning
To pin the Buildx version to a specific release, use the version
input:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.10.0
Pinning BuildKit Image
To pin the BuildKit image to a specific version, use the image
option in the driver-opts
input:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts:
image: moby/buildkit:0.11.0
Using a Dedicated BuildKit Config File
To use a dedicated BuildKit config file from your repository, use the config
input:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config: .github/buildkitd.toml
Multi-platform Builds
To perform multi-platform builds with Buildx, you can use the docker buildx build
command with the --platform
flag:
- name: Build and push multi-platform image
run: |
docker buildx build \
--tag your-username/multiarch-example:latest \
--platform linux/amd64,linux/arm/v7,linux/arm64 .
Environment Variables
Docker Buildx supports various environment variables that impact the behavior of building:
BUILDKIT_PROGRESS
: Configure the type of progress output.BUILDX_BUILDER
: Override the configured builder instance.BUILDX_CONFIG
: Specify the location for configuration, state, and logs.
For a complete list of environment variables, refer to the official documentation.
Additional Resources
- Configuring your GitHub Actions builder | Docker Docs
- Multi-arch build and images, the simple way | Docker
- Docker Github Actions | Docker
- Publishing with Github Actions ยท Cloud Native Buildpacks
- Environment variables for Docker Build | Docker Docs
- Setting Up Cloud Deployments Using Docker, Azure and Github Actions | Docker
- Local registry with GitHub Actions | Docker Docs
- Introduction to GitHub Actions | Docker Docs
- Configure CI/CD for your application | Docker Docs