Skip to content

Commit 0794a26

Browse files
committed
buildkit reference docs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
1 parent 6b71e84 commit 0794a26

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

docs/reference/builder.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ registries.
121121
When you're done with your build, you're ready to look into [*Pushing a
122122
repository to its registry*](https://docs.docker.com/engine/tutorials/dockerrepos/#/contributing-to-docker-hub).
123123

124+
125+
## BuildKit
126+
127+
Starting from version 18.09 Docker supports a new backend for executing your
128+
build that is provided by [moby/buildkit](https://github.com/moby/buildkit)
129+
project. BuildKit backend provides many benefits compared to the old
130+
implementation. For example, BuildKit can:
131+
132+
* Detect and skip executing unused build stages
133+
* Parallelize building independent build stages
134+
* Incrementally transfer only the changed files in your build context between builds
135+
* Detect and skip transferring unused files in your build context
136+
* Use external Dockerfile implementations with many new features
137+
* Avoid leaking dangling images and containers to the rest of the API
138+
* Prioritize your build cache for automatic pruning
139+
140+
To use the BuildKit backend in 18.09, you need to set an environment variable
141+
`DOCKER_BUILDKIT=1` on the CLI before invoking `docker build`.
142+
143+
To learn about the experimental Dockerfile syntax available to BuildKit based
144+
builds [refer to the docs in BuildKit repository](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md).
145+
124146
## Format
125147

126148
Here is the format of the `Dockerfile`:
@@ -226,8 +248,61 @@ following lines are all treated identically:
226248

227249
The following parser directive is supported:
228250

251+
* `syntax`
229252
* `escape`
230253

254+
## syntax
255+
256+
# syntax=[remote image reference]
257+
258+
For example:
259+
260+
# syntax=docker/dockerfile
261+
# syntax=docker/dockerfile:1.0
262+
# syntax=docker/dockerfile:1.0.0-experimental
263+
# syntax=example.com/user/repo:tag@sha256:abcdef...
264+
265+
This feature is only enabled if [BuildKit](#buildkit) backend is used.
266+
267+
Syntax directive defines the location of the Dockerfile builder that is used for
268+
building the current Dockerfile. BuildKit backend allows to seamlessly use
269+
external implementations of builders that are distributed as Docker images and
270+
execute inside a container sandbox environment.
271+
272+
Using a custom Dockerfile implementation allows you to:
273+
- Automatically get bugfixes without updating the daemon
274+
- Make sure all users are using the same implementation to build your Dockerfile
275+
- Use the latest features without updating the daemon
276+
- Try out new experimental or third party features
277+
278+
### Official releases
279+
280+
Docker distributes official versions of the images that can be used for building
281+
Dockerfiles under `docker/dockerfile` repository on Docker Hub. There are two
282+
channels where new images are released: stable and experimental.
283+
284+
Stable channel follows semantic versioning. For example:
285+
286+
- docker/dockerfile:1.0.0 - only allow immutable version 1.0.0
287+
- docker/dockerfile:1.0 - allow versions 1.0.*
288+
- docker/dockerfile:1 - allow versions 1.*.*
289+
- docker/dockerfile:latest - latest release on stable channel
290+
291+
The experimental channel uses incrementing versioning with the major and minor
292+
component from the stable channel on the time of the release. For example:
293+
294+
- docker/dockerfile:1.0.1-experimental - only allow immutable version 1.0.1-experimental
295+
- docker/dockerfile:1.0-experimental - latest experimental releases after 1.0
296+
- docker/dockerfile:experimental - latest release on experimental channel
297+
298+
You should choose a channel that best fits your needs. If you only want
299+
bugfixes, you should use `docker/dockerfile:1.0` while if you're going to use
300+
experimental features, you should use the experimental channel. If you are using
301+
the experimental channel, the new releases may not be backward compatible, so it
302+
is recommended to use an immutable full version variant.
303+
304+
For master builds and nightly feature releases refer to the description in [the source repository](https://github.com/moby/buildkit/blob/master/README.md).
305+
231306
## escape
232307

233308
# escape=\ (backslash)
@@ -1623,6 +1698,31 @@ RUN echo "Hello World"
16231698
When building this Dockerfile, the `HTTP_PROXY` is preserved in the
16241699
`docker history`, and changing its value invalidates the build cache.
16251700

1701+
### Automatic platform ARGs in the global scope
1702+
1703+
This feature is only available when using [BuildKit](#buildkit) backend.
1704+
1705+
Docker has a set of predefined `ARG` variables that are automatically defined with the information based on the current platform of the node performing the build and the platform of the build result specified with the `--platform` flag on `docker build`.
1706+
1707+
* TARGETPLATFORM - platform of the build result. Eg `linux/amd64`, `linux/arm/v7`, `windows/amd64`.
1708+
* TARGETOS - OS component of TARGETPLATFORM
1709+
* TARGETARCH - architecture component of TARGETPLATFORM
1710+
* TARGETVARIANT - variant component of TARGETPLATFORM
1711+
* BUILDPLATFORM - platform of the node performing the build.
1712+
* BUILDOS - OS component of BUILDPLATFORM
1713+
* BUILDARCH - OS component of BUILDPLATFORM
1714+
* BUILDVARIANT - - OS component of BUILDPLATFORM
1715+
1716+
These arguments are defined in the global scope so are not automatically available inside build stages or for your `RUN` commands. To expose one of these arguments inside the build stage redefine it without value.
1717+
1718+
For example:
1719+
1720+
```
1721+
FROM alpine
1722+
ARG TARGETPLATFORM
1723+
RUN echo "I'm building for $TARGETPLATFORM"
1724+
```
1725+
16261726
### Impact on build caching
16271727

16281728
`ARG` variables are not persisted into the built image as `ENV` variables are.
@@ -1931,6 +2031,14 @@ required such as `zsh`, `csh`, `tcsh` and others.
19312031

19322032
The `SHELL` feature was added in Docker 1.12.
19332033

2034+
## Experimental features
2035+
2036+
This feature is only available when using [BuildKit](#buildkit) backend.
2037+
2038+
Docker build supports experimental features like cache mounts, build secrets and
2039+
ssh forwarding that are enabled by using an external implementation of the
2040+
builder with a syntax directive. To learn about these features, [refer to the docs in BuildKit repository](https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/experimental.md).
2041+
19342042
## Dockerfile examples
19352043

19362044
Below you can see some examples of Dockerfile syntax. If you're interested in

0 commit comments

Comments
 (0)