Reputation: 2579
I am exploring the docker build process using the Buildkit. I have enabled it by setting an environment variable DOCKER_BUILDKIT=1
on the CLI before invoking docker build
. From the buildkit documentation it says,
# syntax=docker/dockerfile:1
pointing to the specific image you want to use.and from the syntax documentation it says,
What does this frontend and backend means in terms of docker build process? Can anyone help me to understand it in simple terms?
Upvotes: 14
Views: 2843
Reputation: 1879
TLDR; The frontend and backend concept was born with Buildkit and didn't exist in docker before. Frontend is like a compiler that converts a user's file (eg: Dockerfile) to LLB. Backend executes LLB in the most efficent way to build a docker image.
Without Buildkit, a docker image is built directly using instructions in a Dockerfile. No intermeditate representation of these instructions is created. The instructions are passed to the docker engine (also called the Moby Engine or classic builder) which then builds the image.
Then it was realised that to improve and optimise the build process further most of the fundamentals of the build operation would have to be redefined. Hence a proposal was made to create a new engine, and Buildkit was born along with frontend and backend separation of the build process.
One of the main design goals of buildkit is to separate frontend and backend concerns during a build process. A frontend is something designed for the users to describe their build definition. Backend solves the problem of finding a most efficient way to solve a common low-level description of the build operations, that has been prepared for them by the frontends.
The separation of frontend and backend is acheived by LLB(low-leve builder).
Everything about execution and caching of your builds is defined only in LLB.
Frontends are components that run inside BuildKit and convert any build definition(file written by the user) to LLB. BuildKit supports loading frontends dynamically from container images by specifying: #syntax=...
. A famous frontend is the dockerfile frontend because it is used with the docker engine. You can specify this container image with: #syntax=docker/dockerfile:latest
.
There are plenty of other frontends that can be used, for example the mockerfile frontend with: #syntax=r2d4/mocker
. This then allows you to use a slightly different syntax compared to the usual Dockerfile syntax.
The Buildkit backend solves the LLB generated from any of a variety of frontends. Since the LLB is a dependency graph, it can be processed to: detect and skip executing unused build stages, parallelize building independent build stages etc. This is why Buildkit is able to improve performance, storage management etc. over the older build process. Also, the caching model has been entirely rewritten.
The core part of the builder(Buildkit) is a solver that takes a DAG of low-level build(LLB) instructions from the frontend and finds a way to execute them in a most efficient manner while keeping the cache for the next invocations.
To use the Buildkit backend specifyDOCKER_BUILDKIT=1
.
Starting with version 18.09, Docker supports a new backend for executing your builds that is provided by the moby/buildkit project.
The Moby Engine(the classic builder) can be called the original backend but remember it doesn't use LLB, therefore its build process doesn't have a frontend and backend as such.
References and resouces:
Upvotes: 23