$linuxjunkies
>

docker-buildx(1)

Build images with BuildKit, supporting multiple platforms, caching, and advanced container image creation.

UbuntuDebianFedoraArch

Synopsis

docker buildx [COMMAND]

Description

docker buildx is a Docker CLI plugin that extends the standard docker build command with BuildKit backend capabilities. It enables building container images for multiple platforms simultaneously, supports advanced caching strategies, and provides better performance through parallel builds.

BuildKit is a modern container image builder that offers improved build performance, caching, security, and support for advanced features like secrets and SSH forwarding. Buildx manages BuildKit builder instances and makes them accessible through familiar Docker commands.

Common options

FlagWhat it does
createCreate a new builder instance with a specific driver (docker, docker-container, kubernetes)
useSet the current builder instance to use for subsequent builds
lsList all available builder instances
rmRemove a builder instance
--platformTarget platforms for multi-arch builds, e.g. linux/amd64,linux/arm64
--outputOutput destination (docker, oci, image, etc.); use docker to load into Docker daemon
--cache-toExport build cache to registry or local directory for reuse
--cache-fromImport cache from registry or local source to speed up builds
--secretPass secrets during build without including them in image layers
--sshForward SSH agent to build for private git repository access
--loadLoad built image directly into Docker daemon (single-platform only)
--pushPush image directly to registry after building

Examples

Create a new builder instance using the docker-container driver for advanced features

docker buildx create --name mybuilder --driver docker-container

Switch to the mybuilder instance for subsequent builds

docker buildx use mybuilder

Build image for both AMD64 and ARM64 platforms and push to registry

docker buildx build --platform linux/amd64,linux/arm64 -t myimage:latest --push .

Build image and load it directly into the local Docker daemon

docker buildx build -t myimage:latest --load .

Build with secret injection and SSH agent forwarding for secure builds

docker buildx build --secret id=mytoken --ssh default .

Build with local cache export and import to speed up rebuilds

docker buildx build --cache-to type=local,dest=./buildcache --cache-from type=local,src=./buildcache -t myimage .

List all available builder instances and their details

docker buildx ls

Build for ARM64 and output as OCI image tarball instead of pushing to registry

docker buildx build --platform linux/arm64 --output type=oci,dest=./output .