Skip to content

BuildKit standalone — the image builder without Docker

Run BuildKit as a standalone daemon for image builds — frontends, cache export, multi-platform, and the CI runner pattern with buildkitd over TCP.

BuildKit is the image builder Docker shipped to replace the legacy builder, but it works fine on its own — a daemon (buildkitd) plus a CLI (buildctl) — without any Docker installed. For CI runners that need to build images without granting Docker-daemon access, for build farms that share one BuildKit across many runners, and for multi-platform builds without QEMU dance, the standalone install is the right pick.

How to verify

A working standalone BuildKit responds to these probes:

buildkitd --version
buildctl --version
ls /run/buildkit/buildkitd.sock 2>/dev/null
systemctl is-active buildkit
buildctl debug workers
buildctl debug info

buildctl debug workers lists the configured workers. Each worker has a snapshotter (overlayfs is the common one), a runner (runc), and a set of supported platforms.

What’s happening

BuildKit decouples three things that the legacy Docker builder coupled together. Frontends parse build inputs into a build graph — the default dockerfile.v0 frontend reads a Dockerfile, but other frontends (buildkit-syntax-mockerfile, custom HCL frontends) read different formats. Solvers execute the graph efficiently, with shared caching, parallel execution, and lazy fetching. Workers actually run the build steps, with containerd or OCI snapshotters underneath.

Standalone deployment means running buildkitd as a daemon listening on a Unix socket (default /run/buildkit/buildkitd.sock) or a TCP port (with mTLS), and pointing buildctl at it. For CI, the daemon runs on a shared build host with fast disk and lots of RAM, and runners connect over the network — one daemon shared across many concurrent builds, with cache reuse across builds for free.

The build cache is the killer feature: layer hashes are content-addressable, and the --cache-to/--cache-from flags let cache be exported to a registry. Two CI runners building the same Dockerfile against the same git ref reuse each other’s layers when both point at the same remote cache.

The procedure

  1. Install BuildKit from the upstream release. The Ubuntu package is generally far behind:
BUILDKIT_VERSION=v0.13.2
ARCH=$(dpkg --print-architecture)
curl -fsSL https://github.com/moby/buildkit/releases/download/${BUILDKIT_VERSION}/buildkit-${BUILDKIT_VERSION}.linux-${ARCH}.tar.gz \
  | sudo tar -xz -C /usr/local
sudo install -m 0755 -d /etc/buildkit
  1. Configure the daemon. The defaults are sensible, but cache and worker tuning matter for build farms:
# /etc/buildkit/buildkitd.toml
debug = false
root = "/var/lib/buildkit"

[grpc]
address = ["unix:///run/buildkit/buildkitd.sock"]

[worker.oci]
enabled = true
gc = true
gckeepstorage = 9000  # MiB
max-parallelism = 4
snapshotter = "overlayfs"

[[worker.oci.gcpolicy]]
keepBytes = 9663676416
keepDuration = 604800
  1. Run BuildKit as a systemd unit:
# /etc/systemd/system/buildkit.service
[Unit]
Description=BuildKit
Requires=buildkit.socket

[Service]
ExecStart=/usr/local/bin/buildkitd --addr fd://

[Install]
WantedBy=multi-user.target
# /etc/systemd/system/buildkit.socket
[Unit]
Description=BuildKit socket
[Socket]
ListenStream=%t/buildkit/buildkitd.sock
SocketMode=0660
SocketUser=root
SocketGroup=buildkit
[Install]
WantedBy=sockets.target
sudo groupadd -r buildkit
sudo systemctl daemon-reload
sudo systemctl enable --now buildkit.socket buildkit.service
  1. Build an image via buildctl. The frontend reads the Dockerfile from a tarred context:
buildctl build \
  --frontend=dockerfile.v0 \
  --local context=. \
  --local dockerfile=. \
  --output type=image,name=registry.example.com/api:1.2.3,push=true \
  --export-cache type=registry,ref=registry.example.com/api/buildcache:latest \
  --import-cache type=registry,ref=registry.example.com/api/buildcache:latest
  1. Expose BuildKit over TCP with mTLS for remote CI runners:
# generate CA and certificates (omitted for brevity)
sudo mkdir -p /etc/buildkit/certs
# place ca.crt, daemon.crt, daemon.key
# /etc/buildkit/buildkitd.toml
[grpc]
address = ["tcp://0.0.0.0:1234"]

[grpc.tls]
cert = "/etc/buildkit/certs/daemon.crt"
key = "/etc/buildkit/certs/daemon.key"
ca = "/etc/buildkit/certs/ca.crt"
buildctl --addr tcp://buildkit.example.com:1234 \
  --tlscacert /etc/buildkit/client-ca.crt \
  --tlscert /etc/buildkit/client.crt \
  --tlskey /etc/buildkit/client.key \
  build ...
  1. Cross-platform build in a single invocation. BuildKit uses QEMU to emulate non-native platforms — no manual docker buildx dance:
buildctl build \
  --frontend=dockerfile.v0 \
  --local context=. \
  --local dockerfile=. \
  --opt platform=linux/amd64,linux/arm64 \
  --output type=image,name=registry.example.com/api:1.2.3,push=true

The resulting registry tag is a manifest list pointing to both architecture-specific images.

Common pitfalls

  • Running buildkitd on a host without overlayfs and falling back to naive snapshotter, which is unusably slow. The kernel must have overlayfs and the underlying filesystem must support it (ext4 yes, NFS no).
  • Forgetting that the daemon caches in /var/lib/buildkit — that directory grows without bound unless gcpolicy is configured. Disk-full incidents follow.
  • Exposing TCP without mTLS. The BuildKit API has full build-time access to the host — anyone who can reach the port can run arbitrary code. Always mTLS.
  • Using the registry cache backend without considering credentials. Both push and pull need registry auth; CI runners need credentials configured for the cache registry, not just the image registry.
  • Mixing buildctl build invocations against the same buildkitd from multiple users without --build-arg isolation. Build state can leak across builds if hashed cache keys collide.

Stack Harbor runs shared BuildKit farms for clients with many CI runners — see managed operations for the mTLS provisioning, the GC tuning, the registry-cache pattern, and the multi-arch build pipelines we standardise.