MCPcopy Index your code
hub / github.com/moby/buildkit

github.com/moby/buildkit @v0.31.1 sqlite

repository ↗ · DeepWiki ↗ · release v0.31.1 ↗
11,902 symbols 52,975 edges 934 files 1,426 documented · 12% 13 cross-repo links
README

asciicinema example

BuildKit

GitHub Release PkgGoDev CI BuildKit Status CI Frontend Status Go Report Card Codecov

BuildKit is a toolkit for converting source code to build artifacts in an efficient, expressive and repeatable manner.

Key features:

  • Automatic garbage collection
  • Extendable frontend formats
  • Concurrent dependency resolution
  • Efficient instruction caching
  • Build cache import/export
  • Nested build job invocations
  • Distributable workers
  • Multiple output formats
  • Pluggable architecture
  • Execution without root privileges

Read the proposal from https://github.com/moby/moby/issues/32925

Introductory blog post https://blog.mobyproject.org/introducing-buildkit-17e056cc5317

Join #buildkit channel on Docker Community Slack

[!NOTE] If you are visiting this repo for the usage of BuildKit-only Dockerfile features like RUN --mount=type=(bind|cache|tmpfs|secret|ssh), please refer to the Dockerfile reference.

[!NOTE] docker build uses Buildx and BuildKit by default since Docker Engine 23.0. You don't need to read this document unless you want to use the full-featured standalone version of BuildKit.

Used by

BuildKit is used by the following projects:

Quick start

:information_source: For Kubernetes deployments, see examples/kubernetes.

BuildKit is composed of the buildkitd daemon and the buildctl client. While the buildctl client is available for Linux, macOS, and Windows, the buildkitd daemon is only available for Linux and *Windows currently.

The latest binaries of BuildKit are available here for Linux, macOS, and Windows.

Linux Setup

The buildkitd daemon requires the following components to be installed: - runc or crun - containerd (if you want to use containerd worker)

Starting the buildkitd daemon: You need to run buildkitd as the root user on the host.

$ sudo buildkitd

To run buildkitd as a non-root user, see docs/rootless.md.

The buildkitd daemon supports two worker backends: OCI (runc) and containerd.

By default, the OCI (runc) worker is used. You can set --oci-worker=false --containerd-worker=true to use the containerd worker.

We are open to adding more backends.

To start the buildkitd daemon using systemd socket activation, you can install the buildkit systemd unit files. See Systemd socket activation

The buildkitd daemon listens gRPC API on /run/buildkit/buildkitd.sock by default, but you can also use TCP sockets. See Expose BuildKit as a TCP service.

Windows Setup

See instructions and notes at docs/windows.md.

macOS Setup

Homebrew formula (unofficial) is available for macOS.

$ brew install buildkit

The Homebrew formula does not contain the daemon (buildkitd).

For example, Lima can be used for launching the daemon inside a Linux VM.

brew install lima
limactl start template://buildkit
export BUILDKIT_HOST="unix://$HOME/.lima/buildkit/sock/buildkitd.sock"

Build from source

To build BuildKit from source, see .github/CONTRIBUTING.md.

For a buildctl reference, see this document.

Exploring LLB

BuildKit builds are based on a binary intermediate format called LLB that is used for defining the dependency graph for processes running part of your build. tl;dr: LLB is to Dockerfile what LLVM IR is to C.

  • Marshaled as Protobuf messages
  • Concurrently executable
  • Efficiently cacheable
  • Vendor-neutral (i.e. non-Dockerfile languages can be easily implemented)

See solver/pb/ops.proto for the format definition, and see ./examples/README.md for example LLB applications.

Currently, the following high-level languages have been implemented for LLB:

Exploring Dockerfiles

Frontends are components that run inside BuildKit and convert any build definition to LLB. There is a special frontend called gateway (gateway.v0) that allows using any image as a frontend.

During development, Dockerfile frontend (dockerfile.v0) is also part of the BuildKit repo. In the future, this will be moved out, and Dockerfiles can be built using an external image.

Building a Dockerfile with buildctl

buildctl build \
    --frontend=dockerfile.v0 \
    --local context=. \
    --local dockerfile=.
# or
buildctl build \
    --frontend=dockerfile.v0 \
    --local context=. \
    --local dockerfile=. \
    --opt target=foo \
    --opt build-arg:foo=bar

--local exposes local source files from client to the builder. context and dockerfile are the names Dockerfile frontend looks for build context and Dockerfile location.

If the Dockerfile has a different filename it can be specified with --opt filename=./Dockerfile-alternative.

Building a Dockerfile using external frontend

External versions of the Dockerfile frontend are pushed to https://hub.docker.com/r/docker/dockerfile-upstream and https://hub.docker.com/r/docker/dockerfile and can be used with the gateway frontend. The source for the external frontend is currently located in ./frontend/dockerfile/cmd/dockerfile-frontend but will move out of this repository in the future (#163). For automatic build from master branch of this repository docker/dockerfile-upstream:master or docker/dockerfile-upstream:master-labs image can be used.

buildctl build \
    --frontend gateway.v0 \
    --opt source=docker/dockerfile \
    --local context=. \
    --local dockerfile=.
buildctl build \
    --frontend gateway.v0 \
    --opt source=docker/dockerfile \
    --opt context=https://github.com/moby/moby.git \
    --opt build-arg:APT_MIRROR=cdn-fastly.deb.debian.org

Output

By default, the build result and intermediate cache will only remain internally in BuildKit. An output needs to be specified to retrieve the result.

Image/Registry

buildctl build ... --output type=image,name=docker.io/username/image,push=true

To export the image to multiple registries:

buildctl build ... --output type=image,\"name=docker.io/username/image,docker.io/username2/image2\",push=true

To export the cache embed with the image and pushing them to registry together, type registry is required to import the cache, you should specify --export-cache type=inline and --import-cache type=registry,ref=.... To export the cache to a local directly, you should specify --export-cache type=local. Details in Export cache.

buildctl build ...\
  --output type=image,name=docker.io/username/image,push=true \
  --export-cache type=inline \
  --import-cache type=registry,ref=docker.io/username/image

Keys supported by image output: * name=<value>: specify image name(s) * push=true: push after creating the image * push-by-digest=true: push unnamed image * registry.insecure=true: push to insecure HTTP registry * oci-mediatypes=true: use OCI mediatypes in configuration JSON instead of Docker's * oci-artifact=false: use OCI artifact format for attestations * unpack=true: unpack image after creation (for use with containerd) * dangling-name-prefix=<value>: name image with prefix@<digest>, used for anonymous images * name-canonical=true: add additional canonical name name@<digest> * compression=<uncompressed|gzip|estargz|zstd>: choose compression type for layers newly created and cached, gzip is default value. estargz should be used with oci-mediatypes=true. * compression-level=<value>: compression level for gzip, estargz (0-9) and zstd (0-22) * rewrite-timestamp=true: rewrite the file timestamps to the SOURCE_DATE_EPOCH value. See [docs/build-repro.md](docs

Extension points exported contracts — how you extend this code

SupportsSingleWordExpansion (Interface)
SupportsSingleWordExpansion interface allows a command to support variable. [11 implementers]
frontend/dockerfile/instructions/commands.go
CacheExporterTarget (Interface)
CacheExporterTarget defines object capable of receiving exports [14 implementers]
solver/types.go
SourcePolicyEvaluator (Interface)
SourcePolicyEvaluator evaluates source operations against configured policies. [10 implementers]
solver/llbsolver/policy.go
Attachable (Interface)
Attachable defines a feature that can be exposed on a session [15 implementers]
session/session.go
ProxyPolicy (Interface)
ProxyPolicy authorizes requests made through a BuildKit-owned exec proxy. [10 implementers]
util/network/proxy.go
Source (Interface)
Source implementations provide "root" vertices in the graph that can be constructed from a URI-like string and arbitrary [5 …
source/manager.go
Type (Interface)
Type represents compression type for blob data, which needs to be implemented for each compression type. [5 implementers]
util/compression/compression.go
MutableRef (Interface)
(no doc) [13 implementers]
cache/refs.go

Core symbols most depended-on inside this repo

Equal
called by 2562
util/stack/compress.go
Context
called by 1475
session/manager.go
Equal
called by 809
solver/llbsolver/provenance/types/types.go
copy
called by 719
examples/gobuild/main.go
Close
called by 654
cache/manager.go
String
called by 621
util/compression/compression.go
Marshal
called by 581
client/llb/state.go
New
called by 511
cache/manager.go

Shape

Method 6,373
Function 3,789
Struct 1,360
Interface 208
FuncType 88
TypeAlias 84

Languages

Go100%

Modules by API surface

frontend/gateway/pb/gateway_vtproto.pb.go541 symbols
frontend/gateway/pb/gateway.pb.go527 symbols
solver/pb/ops.pb.go523 symbols
solver/pb/ops_vtproto.pb.go484 symbols
api/services/control/control.pb.go294 symbols
api/services/control/control_vtproto.pb.go243 symbols
client/client_test.go241 symbols
frontend/dockerfile/dockerfile_test.go199 symbols
source/git/source_test.go157 symbols
solver/errdefs/errdefs_vtproto.pb.go109 symbols
cache/metadata.go104 symbols
solver/scheduler_test.go101 symbols

Dependencies from manifests, versioned

cyphar.com/go-pathrsv0.2.1 · 1×
github.com/Azure/azure-sdk-for-go/sdk/azcorev1.21.1 · 1×
github.com/Azure/azure-sdk-for-go/sdk/azidentityv1.13.1 · 1×
github.com/Azure/azure-sdk-for-go/sdk/internalv1.12.0 · 1×
github.com/Azure/azure-sdk-for-go/sdk/storage/azblobv1.5.0 · 1×
github.com/AzureAD/microsoft-authentication-library-for-gov1.7.0 · 1×
github.com/Microsoft/go-winiov0.6.2 · 1×
github.com/Microsoft/hcsshimv0.14.1 · 1×
github.com/ProtonMail/go-cryptov1.3.0 · 1×
github.com/agext/levenshteinv1.2.3 · 1×
github.com/anchore/go-struct-converterv0.1.0 · 1×
github.com/armon/circbufv0.0.0-2019021419053 · 1×

For agents

$ claude mcp add buildkit \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact