Docker BuildKit

Glenn Bostoen
2 min readNov 7, 2019

--

There is a new way to build your Dockerfile with BuildKit. BuildKit is a Dockerfile agnostic builder toolkit which allows you to build your images in a concurrent and cache-efficient way according to their github repo.

You can enable it for your docker builds by enabling the following environment variable:

DOCKER_BUILDKIT=1

You can also enable docker buildkit by default, by setting thedaemon configuration in /etc/docker/daemon.json feature to true and restart the daemon.

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

New Docker build TTY output looks like this:

$ docker build . 
[+] Building 70.9s (34/59)
=> [runc 1/4] COPY hack/dockerfile/install/install.sh ./install.sh 14.0s
=> [frozen-images 3/4] RUN /download-frozen-image-v2.sh /build buildpa 24.9s
=> [containerd 4/5] RUN PREFIX=/build/ ./install.sh containerd 37.1s
=> [tini 2/5] COPY hack/dockerfile/install/install.sh ./install.sh 4.9s
=> [vndr 2/4] COPY hack/dockerfile/install/vndr.installer ./ 1.6s
=> [dockercli 2/4] COPY hack/dockerfile/install/dockercli.installer ./ 5.9s
=> [proxy 2/4] COPY hack/dockerfile/install/proxy.installer ./ 15.7s
=> [tomlv 2/4] COPY hack/dockerfile/install/tomlv.installer ./ 12.4s
=> [gometalinter 2/4] COPY hack/dockerfile/install/gometalinter.install 25.5s
=> [vndr 3/4] RUN PREFIX=/build/ ./install.sh vndr 33.2s
=> [tini 3/5] COPY hack/dockerfile/install/tini.installer ./ 6.1s
=> [dockercli 3/4] RUN PREFIX=/build/ ./install.sh dockercli 18.0s
=> [runc 2/4] COPY hack/dockerfile/install/runc.installer ./ 2.4s
=> [tini 4/5] RUN PREFIX=/build/ ./install.sh tini 11.6s
=> [runc 3/4] RUN PREFIX=/build/ ./install.sh runc 23.4s
=> [tomlv 3/4] RUN PREFIX=/build/ ./install.sh tomlv 9.7s
=> [proxy 3/4] RUN PREFIX=/build/ ./install.sh proxy 14.6s
=> [dev 2/23] RUN useradd --create-home --gid docker unprivilegeduser 5.1s
=> [gometalinter 3/4] RUN PREFIX=/build/ ./install.sh gometalinter 9.4s
=> [dev 3/23] RUN ln -sfv /go/src/github.com/docker/docker/.bashrc ~/.ba 4.3s
=> [dev 4/23] RUN echo source /usr/share/bash-completion/bash_completion 2.5s
=> [dev 5/23] RUN ln -s /usr/local/completion/bash/docker /etc/bash_comp 2.1s

It was released in 18.09 release of Docker but went unnoticed because it’s still hidden behind an experimental feature flag. The integration of BuildKit should show users an improvement on performance, storage management, feature functionality, and security.

  • Docker images created with BuildKit can be pushed to Docker Hub and DTR just like Docker images created with legacy build
  • the Dockerfile format that works on legacy build will also work with BuildKit builds
  • The new --secret command line option allows the user to pass secret information for building new images with a specified Dockerfile

--

--