Buildkit not working with docker-compose in Linux


I’m trying to build my docker application on Linux, but am having trouble getting buildkit to work. My Dockerfile uses the --mount flag, and I’ve verified it on Windows as working fine.

On my Linux machine, I’ve updated the /etc/docker/daemon.json file, exported the DOCKER_BUILDKIT=1 environment variable, and restarted the docker daemon. However, when I try to build using docker-compose, I’m getting the following error:

root@machine:~/repo# docker-compose up --build -d
Step 16/44 : RUN --mount=type=cache,target=/root/.m2 mvn install -P docker
ERROR: Service 'backend' failed to build: the --mount option requires BuildKit. Refer to to learn how to build images with BuildKit enabled

Would appreciate any pointers on how to enable it correctly.

Configuration output:

root@machine:~/repo# echo $DOCKER_BUILDKIT

root@machine:~/repo# cat /etc/docker/daemon.json
  "features": {
    "buildkit" : true

root@machine:~/repo# docker-compose version
docker-compose version 1.25.0, build unknown
docker-py version: 4.1.0
CPython version: 3.8.10
OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020

root@machine:~/repo# docker version
Client: Docker Engine - Community
 Version:           20.10.22
 API version:       1.41
 Go version:        go1.18.9
 Git commit:        3a2c30b
 Built:             Thu Dec 15 22:28:08 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
  Version:          20.10.22
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.9
  Git commit:       42c8b31
  Built:            Thu Dec 15 22:25:58 2022
  OS/Arch:          linux/amd64
  Experimental:     false
  Version:          1.6.14
  GitCommit:        9ba4b250366a5ddde94bb7c9d1def331423aa323
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
  Version:          0.19.0
  GitCommit:        de40ad0

You are using an old Docker Compose version. On Windows you are probably running Docker Compose 2.x. Have you tried installing compose v2?

1 Like

Thanks so much. Didn’t know I needed to get a new version of compose. Installed the latest plugin and switched from docker-compose up to docker compose up and all is well.