bollard icon indicating copy to clipboard operation
bollard copied to clipboard

Error while building an image: the --mount option requires BuildKit. Refer to https://docs.docker.com/go/buildkit/ to learn how to build images with BuildKit enabled

Open Yoric opened this issue 2 years ago • 2 comments

I receive this error while attempting to build https://github.com/matrix-org/synapse/ (the Dockerfile is in docker/Dockerfile).

I haven't found a way to work around this with Bollard yet. I don't know if it's something that needs to be added to/made easier to find in the documentation or something that requires a code change.

According to my logs

{
  "Platform": {
    "Name": ""
  },
  "Components": [
    {
      "Name": "Engine",
      "Version": "20.10.12",
      "Details": {
        "ApiVersion": "1.41",
        "Arch": "amd64",
        "BuildTime": "2022-02-10T15:03:35.000000000+00:00",
        "Experimental": "false",
        "GitCommit": "20.10.12-0ubuntu2~20.04.1",
        "GoVersion": "go1.16.2",
        "KernelVersion": "5.4.0-113-generic",
        "MinAPIVersion": "1.12",
        "Os": "linux"
      }
    },
    {
      "Name": "containerd",
      "Version": "1.5.9-0ubuntu1~20.04.4",
      "Details": {
        "GitCommit": ""
      }
    },
    {
      "Name": "runc",
      "Version": "1.1.0-0ubuntu1~20.04.1",
      "Details": {
        "GitCommit": ""
      }
    },
    {
      "Name": "docker-init",
      "Version": "0.19.0",
      "Details": {
        "GitCommit": ""
      }
    }
  ],
  "Version": "20.10.12",
  "ApiVersion": "1.41",
  "MinAPIVersion": "1.12",
  "GitCommit": "20.10.12-0ubuntu2~20.04.1",
  "GoVersion": "go1.16.2",
  "Os": "linux",
  "Arch": "amd64",
  "KernelVersion": "5.4.0-113-generic",
  "BuildTime": "2022-02-10T15:03:35.000000000+00:00"
}

Yoric avatar May 30 '22 16:05 Yoric

Thanks, that's interesting.. I had a quick look but didn't find a whole lot of documentation or prior art on how this could be done. Going to keep looking..

fussybeaver avatar May 31 '22 06:05 fussybeaver

I'm currently trying to understand how DOCKER_BUILDKIT is interpreted by docker-cli. So far, all I found out is that it involves some internal plug-in: https://github.com/docker/cli/blob/1c5256d8e170225b0a84a5e1a56ff2c7d2374e3c/cmd/docker/builder.go#L90.

I suspect that the plug-in is https://github.com/docker/buildx .

Yoric avatar May 31 '22 07:05 Yoric

This is no way near working, but I've been toying with having bollard call the docker API to use buildkit and opened what I have so far in this PR https://github.com/fussybeaver/bollard/pull/264.

Buildkit is the new default backend the docker CLI uses for building docker images, and comes with a host of improvements like secrets & SSH key artifacts no longer in image layers.

The PR needs a lot more work, but it might help

cmac4603 avatar Oct 16 '22 22:10 cmac4603

A PR landed in master that addresses the buildkit implementation. Please test it to see if it works for you, and/or let me know if you need help getting it working. There is an example that builds a tarball prior to invoking the API - I think you'll need to do the same with Synapse, because there are some additional files needed by Synapse when building the container.

fussybeaver avatar Dec 10 '22 14:12 fussybeaver

Just ran the example, works really nicely :+1:

cmac4603 avatar Dec 12 '22 19:12 cmac4603