-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
- Loading branch information
1 parent
85935a3
commit 5240975
Showing
3 changed files
with
147 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Dockerfile frontend experimental syntaxes | ||
|
||
The contents of this document is planned to be moved to https://docs.docker.com in future. | ||
|
||
## Note for Docker users | ||
|
||
If you are using Docker v18.06 or later, BuildKit mode can be enabled by setting `export DOCKER_BUILDKIT=1` on the client side. | ||
Docker v18.06 also requires the daemon to be running as the experimental mode. | ||
|
||
You need to use `docker build` CLI instead of `buildctl` CLI mentioned in this document. | ||
See [the `docker build` document](https://docs.docker.com/engine/reference/commandline/build/) for the usage. | ||
|
||
Note that not all upstream BuildKit features are available in Docker BuildKit-mode. | ||
|
||
## Use experimental Dockerfile frontend | ||
The features mentioned in this document are experimentally available as [`tonistiigi/dockerfile:master-experimental`](https://hub.docker.com/r/tonistiigi/dockerfile/tags/) image. | ||
|
||
To use the experimental features, the first line of your Dockerfile needs to be `# syntax=tonistiigi/dockerfile:master-experimental`. | ||
As the experimental syntaxes may change in future revisions, you may want to pin the image to a specific revision. | ||
|
||
NOTE: `tonistiigi/dockerfile` is planned to be renamed to `docker/dockerfile-upstream` soon. See [#528](https://github.com/moby/buildkit/issues/528). | ||
|
||
## Experimental syntaxes | ||
|
||
### `RUN --mount=type=bind` (the default mount type) | ||
|
||
This mount type allows binding directories (read-only) in the context or in an image to the build container. | ||
|
||
|Option |Description| | ||
|---------------------|-----------| | ||
|`target`(required) | Mount path.| | ||
|`source` | Source path in the `from`. Defaults to the root of the `from`.| | ||
|`from` | Image name. Defaults to the build context.| | ||
|
||
|
||
### `RUN --mount=type=cache` | ||
|
||
This mount type allows the build container to cache directories for compilers and package managers. | ||
|
||
|Option |Description| | ||
|---------------------|-----------| | ||
|`id` | ID of the cache.| | ||
|`target`(required) | Mount path.| | ||
|`ro`,`readonly` | Read-only if set.| | ||
|`sharing` | Either one of `shared`, `private`, or `locked`. Defaults to `shared`. `shared` cache mount can be used concurrently by multiple writers. `private` creates a new mount if there are multiple writers. `locked` pauses second writer until first one releases the mount.| | ||
|
||
|
||
Example: cache Go packages | ||
|
||
```dockerfile | ||
# syntax = tonistiigi/dockerfile:master-experimental | ||
FROM golang | ||
... | ||
RUN --mount=type=cache,target=/root/.cache/go-build go build ... | ||
``` | ||
|
||
Example: cache apt packages | ||
|
||
```dockerfile | ||
# syntax = tonistiigi/dockerfile:master-experimental | ||
FROM ubuntu | ||
RUN rm -f /etc/apt/apt.conf.d/docker-clean; echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache | ||
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \ | ||
apt update && apt install -y gcc | ||
``` | ||
|
||
### `RUN --mount=type=tmpfs` | ||
|
||
This mount type allows mounting tmpfs in the build container. | ||
|
||
|Option |Description| | ||
|---------------------|-----------| | ||
|`target`(required) | Mount path.| | ||
|
||
|
||
### `RUN --mount=type=secret` | ||
|
||
This mount type allows the build container to access credential files such as AWS keys without baking them into the image. | ||
|
||
|Option |Description| | ||
|---------------------|-----------| | ||
|`id` | ID of the secret. Defaults to `path.Base(target)`.| | ||
|`target` | Mount path. Defaults to `/run/secrets/ + path.Base(id)`.| | ||
|`required` | If set to `true`, the instruction errors out when the secret is unavailable. Defaults to `false`.| | ||
|
||
|
||
Example: access to S3 | ||
|
||
```dockerfile | ||
# syntax = tonistiigi/dockerfile:master-experimental | ||
FROM python:3 | ||
RUN pip install awscli | ||
RUN --mount=type=secret,id=aws,target=/root/.aws/credentials aws s3 cp s3://... ... | ||
``` | ||
|
||
```console | ||
$ buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. \ | ||
--secret id=aws,src=$HOME/.aws/credentials | ||
``` | ||
|
||
### `RUN --mount=type=ssh` | ||
|
||
This mount type allows the build container to access SSH keys, with support for passphrases. | ||
|
||
|Option |Description| | ||
|---------------------|-----------| | ||
|`required` | If set to `true`, the instruction errors out when the key is unavailable. Defaults to `false`.| | ||
|
||
|
||
Example: access to Gitlab | ||
|
||
```dockerfile | ||
# syntax = tonistiigi/dockerfile:master-experimental | ||
FROM alpine | ||
RUN apk add --no-cache openssh-client | ||
RUN mkdir -p -m 0700 ~/.ssh && ssh-keyscan gitlab.com >> ~/.ssh/known_hosts | ||
RUN --mount=type=ssh ssh git@gitlab.com | tee /hello | ||
# "Welcome to GitLab, @GITLAB_USERNAME_ASSOCIATED_WITH_SSHKEY" should be printed here | ||
``` | ||
|
||
```console | ||
$ eval $(ssh-agent) | ||
$ ssh-add ~/.ssh/id_rsa | ||
(Input your passphrase here) | ||
$ buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. \ | ||
--ssh default=$SSH_AUTH_SOCK | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters