Buildkit or Build Enhancements for Docker

Enable Buildkit

For docker build command

We need to define this variable : DOCKER_BUILDKIT=1.
At each execution :
DOCKER_BUILDKIT=1 docker build -t fooTag .

Or we could also export it as an environment variable :
export DOCKER_BUILDKIT=1 # or configure in daemon.json
So only that is needed now :
docker build -t fooTag .

For docker-compose build command

We need to define the variable declared for docker build :  DOCKER_BUILDKIT=1. but also another one : COMPOSE_DOCKER_CLI_BUILD=1.
At each execution :
COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build

Or we could also export it as environment variables :
export DOCKER_BUILDKIT=1 # or configure in daemon.json
export COMPOSE_DOCKER_CLI_BUILD=1
So only that is needed now :
docker-compose build

In Dockerfile

We need to enable experimental feature as first line of the Dockerfile :

# syntax=docker/dockerfile:experimental

Buildkit cache

Cache features

Clear cache

docker builder prune --filter type=exec.cachemount

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *