Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable BuildKit with docker-compose?

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?

like image 929
Archimedes Trajano Avatar asked Oct 28 '19 13:10

Archimedes Trajano


People also ask

How do I enable BuildKit docker?

To enable BuildKit builds Easiest way from a fresh install of docker is to set the DOCKER_BUILDKIT=1 environment variable when invoking the docker build command, such as: $ DOCKER_BUILDKIT=1 docker build .

Does Docker Compose use BuildKit?

And the good news is that Docker Compose 1.25. 1 – that was just released early January – includes BuildKit support! BuildKit support for Docker Compose is actually achieved by redirecting the docker-compose build to the Docker CLI with a limited feature set.

Is BuildKit enabled by default?

Enabling BuildKit in your build If you're using Docker Desktop on macOS or Windows: If you've newly installed it since October 2020, or have reset to factory defaults, BuildKit will be enabled by default for all builds. You can turn it on/off for all builds in Preferences > Docker Engine.

What is the docker BuildKit?

Docker BuildKit is the next generation container image builder, which helps us to make Docker images more efficient, secure, and faster. It's integrated into the Docker release version v18.06. BuildKit is a part of the Moby project which was developed after learning's and failures to make the image build process -


2 Answers

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

like image 197
BMitch Avatar answered Sep 19 '22 11:09

BMitch


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/

like image 34
veben Avatar answered Sep 22 '22 11:09

veben