DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
followed by BuildKit is currently disabled means DOCKER_BUILDKIT=0
is set where the build runs. It is a warning: the image still built. Remove the variable
and docker build uses BuildKit again.
The message names its own fix: "enable it by removing the DOCKER_BUILDKIT=0 environment-variable". In the test, setting the variable to nothing in the same PowerShell session brought back the BuildKit output.
The error
...
$env:DOCKER_BUILDKIT = '0'
...
cmd /c "docker build -t fix12-dkbuild-legacy . 2>&1"; Write-Output "exit=$LASTEXITCODE"
...
DEPRECATED: The legacy builder is deprecated and will be removed in a future release.
BuildKit is currently disabled; enable it by removing the DOCKER_BUILDKIT=0
environment-variable.
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM alpine:latest
---> 294b683cb724
Step 2/3 : RUN echo hello > /hello.txt
---> Running in daab9c3ed4b8
---> Removed intermediate container daab9c3ed4b8
---> 4eb5f8a180b1
Step 3/3 : CMD ["cat", "/hello.txt"]
---> Running in 370d239d0217
---> Removed intermediate container 370d239d0217
---> 8a01867ad409
Successfully built 8a01867ad409
Successfully tagged fix12-dkbuild-legacy:latest
exit=0
Why it happens
DOCKER_BUILDKIT=0 switches docker build to the older builder. The
output shows the switch: Sending build context to Docker daemon and numbered
Step 1/3 lines, where the run with the variable cleared printed
#1, #2 steps. The build finished, tagged the image and returned exit code 0, so a script that
checks only the exit code carries on; the warning is the one sign.
If you did not set it in this terminal, it may come from a script, a CI file or a shell
profile that sets it (not checked here). In PowerShell a bare $env:DOCKER_BUILDKIT
printed 0 while the variable was set and nothing after it was cleared, and
Test-Path Env:DOCKER_BUILDKIT then printed False.
The fix
$env:DOCKER_BUILDKIT = $null
...
cmd /c "docker build --progress=plain -t fix12-dkbuild-legacy2 . 2>&1"; Write-Output "exit=$LASTEXITCODE"
...
#0 building with "desktop-linux" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 110B 0.0s done
#1 DONE 0.1s
...
#5 [2/2] RUN echo hello > /hello.txt
#5 DONE 0.4s
...
#6 unpacking to docker.io/library/fix12-dkbuild-legacy2:latest 0.1s done
#6 DONE 0.9s
exit=0
Setting the variable to $null removes it from the PowerShell session, and the
next build ran on BuildKit with no warning (--progress=plain was added only to
print the steps as plain lines). If the variable comes from your user or system environment,
remove it there too and open a new terminal, or it comes back (not run here).
How it was reproduced
A three-line Dockerfile on the cached alpine:latest (image id 294b683cb724),
built on Docker Desktop 4.99.0 for Windows with client and engine 29.9.3 and buildx v0.38.1.
The variable was set in one PowerShell session for one build and cleared before the next;
the build commands ran in cmd, started from that session as
cmd /c "... 2>&1", so they inherited it. The folder
lab\legacy and the image tags fix12-dkbuild-legacy and
fix12-dkbuild-legacy2 are the test's own.
Frequently asked
- How do I fix 'The legacy builder is deprecated' in docker build?
- Remove the DOCKER_BUILDKIT=0 variable. In PowerShell $env:DOCKER_BUILDKIT = $null did it in the test, and the next docker build ran on BuildKit with no warning.
- Does the legacy builder deprecation warning fail the build?
- No. In the test the build with DOCKER_BUILDKIT=0 printed the warning, tagged the image and ended with exit code 0.
- How can I tell whether docker build used BuildKit?
- In the two test captures the BuildKit run printed numbered steps such as #1 [internal] load build definition, and the legacy run printed Sending build context to Docker daemon and Step 1/3 lines.
More decoded errors in the Fixes category. The same DEPRECATED line with "Install the buildx component" in its second line, and the error that replaces it, are in BuildKit is enabled but the buildx component is missing or broken.