How do you enable BuildKit with docker-compose?

DockerDocker ComposeDocker Buildkit

Docker Problem Overview


I tried export DOCKER_BUILDKIT=1 before a docker-compose build command and I did not see the expected BuildKit output. What did I miss?

Docker Solutions


Solution 1 - Docker

Support for BuildKit was just released in docker-compose 1.25.0. To enable:

export DOCKER_BUILDKIT=1 # or configure in daemon.json
export COMPOSE_DOCKER_CLI_BUILD=1

With those variables set in your shell, you can now run docker-compose build using BuildKit.

In windows you can execute in your console:

setx DOCKER_BUILDKIT 1 # or configure in daemon.json
setx COMPOSE_DOCKER_CLI_BUILD 1

after will need restart your console

Solution 2 - Docker

You can use this command to tell docker-compose to use the Docker CLI when executing a build.

COMPOSE_DOCKER_CLI_BUILD=1 docker-compose build

You should see the same build as usual, but with this warning:

> WARNING: Native build is an experimental feature and could change at > any time

And you can go like that to parametrize the CLI to use BuildKit instead of the default builder:

COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build

Windows version:

set "COMPOSE_DOCKER_CLI_BUILD=1" & set "DOCKER_BUILDKIT=1" & docker-compose build

You can also enable BuildKit globally, editing /etc/docker/daemon.json file, adding:

{ "features": { "buildkit": true } }

For more informations: https://docs.docker.com/develop/develop-images/build_enhancements/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionArchimedes TrajanoView Question on Stackoverflow
Solution 1 - DockerBMitchView Answer on Stackoverflow
Solution 2 - DockervebenView Answer on Stackoverflow