コンテンツへスキップ
LatchkeyLatchkey home

Docker Buildx対BuildKit:両者の関係

これらは競合ではありません。BuildKitは現代的なDockerのビルドエンジンであり、BuildxはBuildKitを駆動するCLIプラグインとドライバシステムです。ほぼ常に両者を一緒に使います。

よくある混乱は、BuildxとBuildKitを代替物として扱うことです。BuildKitは実際にイメージをビルドするバックエンド(並行ステージ、cacheマウント、より優れたキャッシング)であり、Buildxはその機能を公開しbuilderを管理するフロントエンドCLI(docker buildx)です。ここでは両者の関係と、CIで何を選ぶべきかを説明します。

Docker BuildxBuildKit
何であるかCLIプラグイン + ドライバマネージャービルドエンジン(バックエンド)
役割ビルド、マルチプラットフォーム、builderを駆動するビルドグラフを実行する
マルチプラットフォームあり(--platform、エミュレーション/ノード)マルチアーキテクチャのエンジンサポート
cacheエクスポートregistry/inline/localのcacheを公開cacheバックエンドを実装
ドライバdocker、docker-container、kubernetes、remote選ばれたドライバ内で動作
関係BuildKitへのフロントエンドBuildxが使うバックエンド

エンジン対フロントエンド

BuildKitはエンジンです。DockerfileをDAGに解析し、独立したステージを並列に実行し、cacheマウント(RUN --mount=type=cache)やシークレットといった高度な機能をサポートします。Buildxはユーザー向けのCLIとドライバ層であり、それらの機能へのアクセス、複数のアーキテクチャ向けのビルド、専用コンテナやKubernetes builderでのビルド実行を可能にします。

Buildxが必要になるとき

単純な単一アーキテクチャのビルドには、docker build(現在はデフォルトでBuildKitに支えられています)で十分です。マルチプラットフォームのイメージ、cacheを保持するコンテナ/リモートbuilder、またはregistryへの明示的なcacheのエクスポート/インポートが必要なときはdocker buildxに手を伸ばしましょう。docker-containerドライバこそが、クロスプラットフォームのビルドと共有可能なcacheを解き放つものです。

CIにおいて

CIでは、各実行が前回の実行のレイヤーを再利用できるよう、registryに対してdocker buildx build --cache-to/--cache-fromを使い、マルチアーキテクチャにはdocker-containerドライバを使いましょう。これにより、冷たく遅いイメージビルドが、cacheヒットの速いビルドに変わります。

Benchmark on your repository before choosing

Build-tool benchmarks published by vendors use repositories chosen to show a difference. Yours is the only one that matters, and both a cold and a warm measurement are needed because CI mostly runs cold.

Terminal
# cold: no cache, the CI condition
rm -rf node_modules/.cache dist && time <tool> build

# warm: the local development condition
time <tool> build

# and the one people forget: incremental after a one-line change
echo "// touch" >> src/index.ts && time <tool> build

結論

両者から選ぶのではありません。BuildKitはエンジンであり、Buildxはそれを駆動するCLIです。マルチプラットフォームのビルドやエクスポート可能なcacheが必要なときはdocker buildxを使いましょう。そうでなければ、BuildKitはすでにデフォルトのdocker buildを支えています。

よくある質問

Docker Buildx vs BuildKit: How They Relate?
A common point of confusion is treating Buildx and BuildKit as alternatives. BuildKit is the backend that actually builds images (concurrent stages, cache mounts, better caching); Buildx is the front-end CLI (docker buildx) that exposes BuildKit features and manages builders. Here is how they relate and what to pick in CI.
Engine vs front-end?
BuildKit is the engine: it parses the Dockerfile into a DAG, runs independent stages in parallel, and supports advanced features like cache mounts (RUN --mount=type=cache) and secrets. Buildx is the user-facing CLI and driver layer that lets you access those features, build for multiple architectures, and run builds in a dedicated
When you need Buildx?
For a plain single-arch build, docker build (now backed by BuildKit by default) is enough. Reach for docker buildx when you need multi-platform images, a container/remote builder that persists cache, or explicit cache export/import to a registry. The docker-container driver is what unlocks cross-platform builds and shareable cache.
In CI?
On CI, use docker buildx build --cache-to/--cache-from against a registry so each run reuses layers from previous runs, and use the docker-container driver for multi-arch. This turns cold, slow image builds into fast, cache-hit builds.
Which should I choose?
Do not choose between them: BuildKit is the engine and Buildx is the CLI that drives it. Use docker buildx when you need multi-platform builds or exportable cache; otherwise BuildKit already powers your default docker build.

関連ガイド