45

I got this command from the documentation, but i really have no idea how can I use it or where should I start to move, I'm new to docker, and concepts are still hard to me to digest:

$ DOCKER_BUILDKIT=1 docker build .

How can I use this command to enable/disable buildkit in docker engine??

I want to disable it, because as i knew it is enabled by default and i suspect it as i can't build anything by docker since i get always this error

failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount847288160/Dockerfile: no such file or directory
dejanualex
  • 3,872
  • 6
  • 22
  • 37
Code Eagle
  • 1,293
  • 1
  • 17
  • 34
  • You simply run the command as you found it and it will run with buildkit. If your remove the `DOCKER_BUILDKIT=1``it will run "normally". If you set that var inside your environment, it will always run with buildkit when in you environment. And if you look at the answer below to change your docker daemon configuration, it will the run run by default in buildkit for anyone using the deamon without having to set the env var. – Zeitounator Mar 28 '21 at 10:24
  • 2
    Sorry, got your problem wrong... See below answer and just change the default value to false. Then my above comment will be valid;) If buildkit is enabled by default in your daemon, without any warranty, you can try `DOCKER_BUILDKIT=0 docker build .` but it is not reported in the documentation and I am not sure that the docker command line will honor it. – Zeitounator Mar 28 '21 at 11:07
  • 1
    @Zeitounator Yes, you're totally right, that variable should be parsed and used for building. Looks like it's done [here](https://github.com/docker/cli/blob/6916b427a0b07e8581d121967633235ced6db9a1/cli/command/cli.go#L174-L186) in the source code. – cam Mar 29 '21 at 03:27

4 Answers4

45

You must adjust the Docker Engine's daemon settings, stored in the daemon.json, and restart the engine. As @Zeitounator suggests, you should be able to temporarily disable the buildkit with DOCKER_BUILDKIT=0 docker build .. Docker CLI will parse that environment variable and should honor it as that checking is done here in the docker/cli source code.

To adjust the Docker daemon's buildkit settings, you can follow the instructions below.

From these docs. Partially on the command line, you can do that this way in Powershell:

  1. Open the file, on the command line the easiest way to do this is:
notepad "$env:USERPROFILE\.docker\daemon.json"
  1. Change the value of "buildkit" to false so it looks like this:
{
  "registry-mirrors": [],
  "insecure-registries": [],
  "debug": true,
  "experimental": false,
  "features": {
    "buildkit": false
  }
}
  1. Restart the Docker service:
Restart-Service *docker*

Alternatively, on Docker Desktop for Windows app:

Open the Dashboard > Settings:

Select Docker Engine and edit the json "features" field to read false if it's not already:

Screenshot of Docker Desktop for Windows app

cam
  • 4,409
  • 2
  • 24
  • 34
  • 3
    You don't "have to" do all this, only if you always want to run with buildkit by default without having to set an env var. – Zeitounator Mar 28 '21 at 10:25
  • 1
    @Zeitounator That's a good point. It seemed like the OP had an issue where buildkit was enabled by default so I was showing how to disable the buildkit on the daemon's settings. – cam Mar 28 '21 at 10:35
  • 1
    chair/keyboard interface on my side. I got the problem wrong... This is definitely the good answer. – Zeitounator Mar 28 '21 at 11:09
  • 1
    Note that starting from [v23](https://github.com/moby/moby/releases/tag/v23.0.0) Docker uses the BuildKit as the new default so if you want to use the `daemon.json` configuration above but **enable** the new BuildKit, make sure to set `buildkit` to `true`. – WebDevPassion Mar 02 '23 at 11:44
3

On Windows 10 x64 and Docker Desktop:

# Start DOS cmd prompt
set DOCKER_BUILDKIT=0
docker ...

No need to edit any files, restart service, etc. It just works as Docker checks the this environment variable when it runs.

Case study

Docker gave an error on the command line when I was logged into a remote PC using MobaXTerm on the command line. This fixed it.

Contango
  • 76,540
  • 58
  • 260
  • 305
2

For me restarting docker engine and system didnt work. But after I reset the factory settings it started working again. Go to Docker desktop troubleshoot options and reset to factory defaults.

2
  1. Open your Docker desktop application

  2. Find settings

  3. Find Docker Engine

  4. You can find below json:

    {
      "builder": {
        "gc": {
          "defaultKeepStorage": "20GB",
          "enabled": true
        }
      },
      "experimental": false,
      "features": {
        "buildkit": false
      }
    }
    
  5. Default value of "buildkit":true -> change to false

  6. Restart the engine

Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45
Reshnu chandran
  • 338
  • 2
  • 6
  • 1
    Noting the Docker Desktop JSON method of disabling buildkit no longer seems to work. It can still be disabled with the environment variable though. – rsethc May 12 '23 at 14:12
  • 1
    works for me with docker engine v23.0.5 – Alex Aug 29 '23 at 03:49