BuildKit and docker buildx

Intermediate · 10 min

BuildKit is the engine behind docker build and buildx is its client. Frontends, LLB, builders and drivers, exporters, and when to create your own builder.

Before thisMulti-stage buildsThe Docker architecture: client, daemon and runtimes

Ardan Labs · 10 min

BuildKit and docker buildx

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Ardan LabsReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • BuildKit is Docker's build engine and has been the default on Linux since Engine 23.0. docker build is now an alias for docker buildx build.
  • A frontend turns a Dockerfile into LLB, a content-addressed graph of build steps. BuildKit solves the graph, running independent steps in parallel and skipping unused ones.
  • A builder is a running BuildKit instance. The default builder uses the docker driver, which is BuildKit embedded in dockerd.
  • Other drivers, such as docker-container, kubernetes, remote and cloud, run BuildKit separately and unlock cache export, multi-platform output and custom configuration.
  • Exporters decide where the result goes: the local image store with --load, a registry with --push, or files with --output type=local or tar.
  • docker buildx ls, create, use, inspect, du, prune and history manage builders, their cache and their build records.

The builder was a bottleneck

The original Docker builder ran a Dockerfile top to bottom, one instruction at a time, committing an intermediate container after each. Stages ran in order even when they did not depend on each other. The whole context was uploaded before the first step. The cache could not leave the machine. Secrets had no safe way in. It worked for small images and fell over for monorepos, cross-platform images and CI.

BuildKit replaced it. It shipped as an opt-in for years and became the default on Linux with Docker Engine 23.0, when docker build also became an alias for docker buildx build. The docs now say the legacy builder is only used for Windows containers. Every advanced build feature in this group, cache and secret mounts, multi-platform and exported caches, needs it.

Frontend, LLB, solver, exporter

BuildKit is a pipeline with replaceable ends:

  1. Frontend. Reads a human format and emits LLB. The Dockerfile frontend is the common one, and the # syntax=docker/dockerfile:1 line picks its version, downloaded as an image. That is why new Dockerfile features work without upgrading Docker.
  2. LLB. Low-Level Build, a content-addressed graph of operations: fetch an image, copy files, run a command. The docs describe it as tracking “the checksums of build graphs and content mounted to specific operations” instead of comparing images by heuristics.
  3. Solver. Walks the graph. Steps with no dependency between them run in parallel. Steps the target does not need are never run. Each step’s cache key comes from its definition and inputs.
  4. Exporter. Writes the result somewhere: the image store, a registry, a directory, a tarball.

Think of it as a compiler. The frontend is the parser, LLB the intermediate representation, the solver an optimizer and scheduler, and the exporter the linker writing the output file. The multi-stage lesson printed a real LLB graph and showed a test stage missing from it because the target did not need it.

Builders and drivers

buildx is the client. A builder is a BuildKit instance it talks to, and a driver says where that instance runs:

Driver Where BuildKit runs Notes from the drivers page
docker Inside dockerd The default. Loads images automatically. Not configurable. Multi-platform and some cache backends need the containerd image store.
docker-container A moby/buildkit container All cache backends and outputs. Results are not loaded unless you ask.
kubernetes BuildKit pods in a cluster Scales out builds in CI.
remote A buildkitd you run yourself Connect over TCP or a socket.
cloud Docker Build Cloud Managed builders with a shared cache.

Managing them:

docker buildx ls                                     # builders and their platforms; * marks the selected one
docker buildx create --name ci --driver docker-container --bootstrap --use
docker buildx inspect ci                             # BuildKit version, platforms, driver options
docker buildx du                                     # build cache disk usage
docker buildx prune --filter until=72h               # delete older cache
docker buildx history ls                             # recent builds; history logs and trace dig in

One trap from the builders page: plain docker build always uses the default builder for backwards compatibility, while docker buildx build uses whichever builder you selected with use. Pass --builder ci to be explicit.

Where the output goes

The exporter is chosen with --output, with two shorthands:

docker buildx build --load -t notes:dev .                       # into the local image store (type=docker)
docker buildx build --push -t registry.example.com/notes:1.4.2 .  # straight to a registry (type=registry)
docker buildx build --target build --output type=local,dest=./out .   # a stage's files onto disk
docker buildx build --output type=tar,dest=rootfs.tar .         # the filesystem as a tarball

The docker driver loads automatically. The others leave the result in the builder’s cache unless you pass --load, --push or --output, which is the most common surprise when switching drivers. type=local is useful beyond images: a build stage that only produces a binary or a test report can write it straight to your disk, so the Dockerfile becomes a reproducible build script.

Bake, briefly

docker buildx bake reads build definitions from an HCL, JSON or Compose file and builds several targets at once, with shared arguments, tags and cache settings. It replaces a shell script full of docker build lines. Its file format is in the bake reference linked from the drivers page. For a single image, plain buildx build is enough.

About the video

The embed is Ardan Labs’ “Docker BuildKit Tutorial: Why do we need a new Docker Builder?”, October 2022, 10.5 minutes, cut from Jérôme Petazzoni’s August 2022 webinar “From Docker Build to Docker Buildx”. Its chapters cover what “Docker Build 3.0” is, why a new builder was needed, BuildKit’s pitch, compatibility, and a demo. It predates BuildKit becoming the Linux default in early 2023, bake’s general availability and build checks, so what it calls new is now standard. YouTube reports an English original audio track. Nick Janetakis’s video in deeper spends its first half on creating and inspecting builders.

What was run: nothing here needs a daemon, and no builder was created. The architecture, driver table, exporter shorthands and command flags are from the BuildKit, builders, drivers and exporters pages in the docker/docs repository and the buildx command reference on GitHub, checked 2026-11-28. The LLB graph referred to was produced earlier with BuildKit v0.35.1 as a Go library.

Where this fits

You know what runs your builds. Next, two BuildKit features the legacy builder never had: cache mounts and build secrets.

Check yourself

  1. 01You build with a docker-container builder and then docker run myapp:dev fails with 'Unable to find image'. Why?

    Builders other than the docker driver do not load results into the local image store by default. The image stayed in the builder's cache. Add --load, or create the builder with --driver-opt default-load=true.

  2. 02What is LLB, and why does it matter for caching?

    LLB is BuildKit's low-level build format, a content-addressed graph of operations. Each operation's cache key comes from its definition and inputs, so BuildKit can reuse, parallelize or skip steps precisely, and even export the cache to a registry.

  3. 03Why might you create a docker-container builder even on a laptop where the default builder works?

    The docker driver only supports some cache export backends unless the containerd image store is on, and it cannot be configured. A docker-container builder supports every cache backend and output type and can be given its own BuildKit config.

  4. 04How do you get the compiled binary out of a build stage onto your disk without making an image?

    Use the local exporter, for example docker buildx build --target build --output type=local,dest=./out . It writes the stage's filesystem to ./out.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark