env.dev

DOCKER_BUILDKIT

When set to 1, enables BuildKit as the default builder for docker build commands. BuildKit provides improved build performance, better caching, and features like build secrets and SSH forwarding. Enabled by default in Docker Engine 23.0+.

Last updated:

DOCKER_BUILDKIT=1 switches `docker build` from the legacy builder to BuildKit, which builds independent stages in parallel, skips unused stages, caches more aggressively, and unlocks features like `RUN --mount=type=secret` and `--mount=type=cache`. Since Docker Engine 23.0 (2023) BuildKit is the default, so on modern Docker you rarely need to set it — but the flip side matters more now: setting DOCKER_BUILDKIT=0 forces the old builder, which is exactly what you do when a Dockerfile uses syntax BuildKit rejects or you need the legacy build output.

Provider
Docker
Category
build
Set by
Set via environment variable or Docker daemon configuration
Default
1
Example
1
Gotcha: BuildKit only prints the output of the stages it actually needs, so a `RUN echo ...` in an unreferenced stage simply never appears — people think the command 'did not run'. And build secrets (`RUN --mount=type=secret`) require BuildKit; with DOCKER_BUILDKIT=0 that mount syntax errors out. Conversely, some old CI images still default to the legacy builder, so set DOCKER_BUILDKIT=1 explicitly there.

How to set DOCKER_BUILDKIT

force BuildKit on (older Docker / CI)

DOCKER_BUILDKIT=1 docker build -t myapp .

force the legacy builder

DOCKER_BUILDKIT=0 docker build -t myapp .

use a build secret (BuildKit only)

DOCKER_BUILDKIT=1 docker build \
  --secret id=npmrc,src=$HOME/.npmrc -t myapp .

Frequently Asked Questions

Do I still need to set DOCKER_BUILDKIT=1?

On Docker Engine 23.0+ (2023) BuildKit is already the default, so usually no. Set it explicitly only on older Docker, on CI images that still default to the legacy builder, or set DOCKER_BUILDKIT=0 when you specifically need the legacy builder.

Was this helpful?

Stay up to date

Get notified about new guides, tools, and cheatsheets.

Browse all 242 environment variables →