BuildIntermediate
Docker Buildx Cheatsheet
Next-gen image builder powered by BuildKit, with multi-platform, bake, and history.
What it is
Use Buildx for fast, cached, multi-platform image builds, parallel builds via bake, and to inspect build history and cache usage.
Installation
Bundled with Docker Desktop and modern Docker Engine. `docker build` is an alias for `docker buildx build`. Confirm with `docker buildx version`.
Quick start
docker buildx create --use --name multiCreate and select a builder.
docker buildx build -t app:dev --load .Build and load into local image store.
docker buildx build --platform linux/amd64,linux/arm64 -t me/app:1.0 --push .Multi-arch build pushed to a registry.
docker buildx bakeRun targets defined in docker-bake.hcl / .json / compose.
Common commands
| Task | Command | Description |
|---|---|---|
| Create builder | | Creates a BuildKit builder and switches to it. |
| Select builder | | Switch the active builder. |
| Inspect builder | | Show driver, platforms, status. |
| Build image | | Default builder, current context. |
| Bake targets | | Build one or more targets from HCL/JSON/compose. |
| Cache usage | | Show BuildKit cache disk usage. |
| Build history | | List recent builds with this builder. |
| Open build in UI | | Open a build record in Docker Desktop / Build Cloud UI. |
| Export build record | | Save a portable build record. |
Useful flags
| Flag | Example | Meaning |
|---|---|---|
| --platform | | Comma-separated target platforms. |
| --push | | Push the result to the registry (required for multi-arch). |
| --load | | Load the result into the local image store (single platform only). |
| --cache-from | | Import build cache from a source. |
| --cache-to | | Export build cache to a destination. |
| --build-arg | | Pass a build-time variable. |
| --secret | | Mount a secret into the build (BuildKit). |
Real-world examples
Multi-arch build, push, with registry cache
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=registry,ref=me/app:cache \
--cache-to type=registry,ref=me/app:cache,mode=max \
-t me/app:1.0 --push .Minimal docker-bake.hcl
group "default" { targets = ["api", "web"] }
target "api" { context = "./api" tags = ["me/api:dev"] }
target "web" { context = "./web" tags = ["me/web:dev"] }Pass a secret without baking it into a layer
docker buildx build --secret id=token,env=GITHUB_TOKEN -t app .Best practices
- Create a dedicated builder per project so caches don't compete.
- Use --cache-to/--cache-from with mode=max for shared CI cache.
- Prefer --secret over --build-arg for tokens; --build-arg leaks into image history.
- Use bake to parallelize related builds and keep CI configs in version control.
- For multi-arch images always --push; --load only supports a single platform.
Troubleshooting
ERROR: multiple platforms feature is currently not supported for docker driver
Create a docker-container or cloud builder.
docker buildx create --use --name multiBuild is slow on every run
Wire up a remote cache.
docker buildx build --cache-from type=registry,ref=me/app:cache --cache-to type=registry,ref=me/app:cache,mode=max .Disk full from BuildKit cache
Inspect and prune cache.
docker buildx du && docker buildx prune -afOfficial Docker Docs references
Last reviewed: