BuildKit Fundamentals
BuildKit is a tool that enables efficient and flexible building and packaging of software using containers. It is the default build engine for Docker and is used by the Docker CLI for building images. BuildKit is a project under the Moby umbrella and is meant to replace the internals of the current build features in the Moby Engine.
Key Technologies and Dependencies
- BuildKit: A toolkit for efficient and flexible building of software using containers.
- Docker: A platform for developing, shipping, and running applications using containers.
- Go Programming Language: The programming language used to build and run Docker and BuildKit.
- Go-units: A Go library for working with mount information, signals, and filesystem utilities.
- Docker CLI: The command-line interface for working with Docker.
- Docker Engine: The core Docker platform for building, running, and sharing containers.
- Go Libraries for Docker: Libraries for working with Docker from Go.
- Moby BuildKit: The Moby project’s implementation of BuildKit.
Design Philosophy
BuildKit is designed to improve the performance, storage management, and extensibility of the Docker build experience. It uses a new fully concurrent build graph solver to run build steps in parallel when possible and optimize out commands that don’t have an impact on the final result. BuildKit also optimizes the access to local source files by tracking only the updates made to these files between repeated build invocations.
Programming Languages
BuildKit is written in the Go programming language and is designed to be extensible using the Low-Level Build (LLB) definition format. LLB is an intermediate binary format that allows developers to extend BuildKit and define a content-addressable dependency graph that can be used to put together complex build definitions.
Docker
Docker is a platform for developing, shipping, and running applications using containers. Docker uses BuildKit as the default build engine and provides a command-line interface (CLI) for working with Docker and BuildKit.
Go Libraries for Docker
Go Libraries for Docker are libraries for working with Docker from Go. These libraries provide a convenient way to interact with Docker from Go programs and are used by BuildKit to provide efficient and flexible building of software using containers.
Moby BuildKit
Moby BuildKit is the Moby project’s implementation of BuildKit. It is designed to be a drop-in replacement for the current build features in the Moby Engine and provides improved performance, storage management, and extensibility.
Environment Variables for Docker Build
Docker provides a number of environment variables for configuring the behavior of features related to building. These variables include:
BUILDKIT_COLORS
: Configure text color for the terminal output.BUILDKIT_HOST
: Specify host to use for remote builders.BUILDKIT_PROGRESS
: Configure type of progress output.BUILDX_BUILDER
: Specify the builder instance to use.BUILDX_CONFIG
: Specify location for configuration, state, and logs.BUILDX_EXPERIMENTAL
: Turn on experimental features.BUILDX_GIT_CHECK_DIRTY
: Enable dirty Git checkout detection.BUILDX_GIT_INFO
: Remove Git information in provenance attestations.BUILDX_GIT_LABELS
: Add Git provenance labels to images.BUILDX_NO_DEFAULT_ATTESTATIONS
: Turn off default provenance attestations.BUILDX_NO_DEFAULT_LOAD
: Turn off loading images to image store by default.
Build Drivers
Build drivers are configurations for how and where the BuildKit backend runs. Driver settings are customizable and allow fine-grained control of the builder. Buildx supports the following drivers:
docker
: Uses the BuildKit library bundled into the Docker daemon.docker-container
: Creates a dedicated BuildKit container using Docker.kubernetes
: Creates BuildKit pods in a Kubernetes cluster.remote
: Connects directly to a manually managed BuildKit daemon.
The default docker
driver prioritizes simplicity and ease of use, but has limited support for advanced features like caching and output formats. Other drivers, such as docker-container
and kubernetes
, provide more advanced features and fine-grained control of the builder.
Build Release Notes
The following are the release notes for BuildKit:
- First release: Introduces a new fully concurrent build graph solver, optimized access to local source files, and the Low-Level Build (LLB) definition format.
For more details, see the complete release notes in the Buildx GitHub repository.
Additional Resources
- BuildKit & Docker Buildx
- Docker Build architecture | Docker Docs
- Capturing Build Information with BuildKit | Docker
- Environment variables for Docker Build | Docker Docs
- Build drivers | Docker Docs
- Build release notes | Docker Docs
- docker buildx rm | Docker Docs
- Build · Cloud Native Buildpacks
- Introduction to heredocs in Dockerfiles | Docker
- BuildKit | Docker Docs
- How to Rapidly Build Multi-Architecture Images with Buildx | Docker
- Faster Multi-Platform Builds: Dockerfile Cross-Compilation Guide | Docker
Conclusion
BuildKit is a powerful and flexible tool for building and packaging software using containers. It is designed to improve the performance, storage management, and extensibility of the Docker build experience and provides a number of customizable drivers and environment variables for fine-grained control of the builder. With its Low-Level Build (LLB) definition format and support for multiple programming languages, BuildKit is a versatile and extensible tool for building and packaging software using containers.