|
2 | 2 | title: Building Dockerfile Images with Buildkit
|
3 | 3 |
|
4 | 4 | description: |
|
5 |
| - This guide shows how to install buildkit to allow you to build Dockerfile images with Unikraft. |
| 5 | + This guide shows how to install Buildkit for building Dockerfile images with |
| 6 | + Unikraft. |
6 | 7 | ---
|
7 | 8 |
|
8 |
| -Unikraft uses [BuildKit](https://docs.docker.com/build/buildkit/), along with [Dockerfiles](https://docs.docker.com/reference/dockerfile/), to construct the root filesystem used by applications. |
| 9 | +Unikraft uses [BuildKit][buildkit], along with [Dockerfiles][dockerfiles], to |
| 10 | +construct the root filesystem used by applications. |
9 | 11 |
|
10 |
| -You can install BuildKit by either running it natively via systemd or in a container. |
11 |
| -Please refer to [BuildKit's installation instructions](https://github.com/moby/buildkit) for more information. |
| 12 | +We can install BuildKit either by running it natively via `systemd` or inside a |
| 13 | +container. Please refer to [BuildKit's installation |
| 14 | +instructions][buildkit-installation] for more information. For convenience, we |
| 15 | +recommend running it inside a container. |
12 | 16 |
|
13 |
| -To use BuildKit with Docker on your system, you first need to install Docker following the [official instructions](https://docs.docker.com/engine/install/). |
14 |
| -This can be either [Docker Engine](https://docs.docker.com/engine/) or [Docker Desktop](https://docs.docker.com/desktop/). |
| 17 | +We will also need a [container engine][container-engine] on our host. Popular |
| 18 | +choices include [Docker][docker], [podman], and [containerd]. Please follow |
| 19 | +their respective documentation to get them up and running. For the rest of this |
| 20 | +article, we will assume Docker to be the installed container engine. |
15 | 21 |
|
16 |
| -After installing Docker, you can run BuildKit in a container via: |
| 22 | +After installing the container engine, we can go ahead and run BuildKit. |
17 | 23 |
|
18 | 24 | ```bash
|
19 | 25 | docker run -d --name buildkitd --privileged moby/buildkit:latest
|
20 | 26 | ```
|
21 | 27 |
|
22 |
| -Now instruct `kraft` to use the BuildKit instance from the `buildkitd` container by either setting the environmental variable: |
| 28 | +We can check if the container launched by doing: |
23 | 29 |
|
24 | 30 | ```bash
|
25 |
| -export KRAFTKIT_BUILDKIT_HOST=docker-container://buildkitd |
| 31 | +$ docker container ps | grep buildkitd |
26 | 32 | ```
|
27 | 33 |
|
28 |
| -Or edit KraftKit's configuration file at `~/.config/kraftkit/config.yaml` and set the `buildkit_host` attribute. |
29 |
| - |
30 |
| -To check that it worked you can run the following command: |
31 |
| - |
32 | 34 | ```bash
|
33 |
| -docker container ps | grep buildkit |
| 35 | +b146031cd4db moby/buildkit:latest "buildkitd" About a minute ago Up About a minute buildkit |
34 | 36 | ```
|
35 | 37 |
|
36 |
| -You should see output similar to: |
| 38 | +Now, we instruct `kraft` to use the BuildKit instance we launched. We can do it |
| 39 | +in the following ways: |
| 40 | + |
| 41 | +- `KRAFTKIT_BUILDKIT_HOST` environment variable: |
| 42 | + ```bash |
| 43 | + export KRAFTKIT_BUILDKIT_HOST=docker-container://buildkitd |
| 44 | + ``` |
| 45 | +- KraftKit's configuration file (`~/.config/kraftkit/config.yaml`): |
| 46 | + ```yaml |
| 47 | + buildkit_host: docker-container://buildkitd |
| 48 | + ``` |
| 49 | +- Passing the `--buildkit-host` CLI flag to `kraft`: |
| 50 | + ```bash |
| 51 | + kraft --buildkit-host=docker-container://buildkitd <args> |
| 52 | + ``` |
| 53 | + |
| 54 | +> A container's URI depends on its name and the container engine. For example, a |
| 55 | +> container managed by `podman` will have `podman-container://buildkitd` as its |
| 56 | +> URI. |
| 57 | + |
| 58 | +Since we gave a name to our container, we can use the `start` and `stop` |
| 59 | +subcommands to spawn/stop our BuildKit instance on demand. |
37 | 60 |
|
38 | 61 | ```bash
|
39 |
| -b146031cd4db moby/buildkit:latest "buildkitd" About a minute ago Up About a minute buildkit |
| 62 | +docker stop buildkitd # Start the container |
| 63 | +docker start buildkitd # Stop the container |
40 | 64 | ```
|
| 65 | + |
| 66 | +[buildkit]: https://docs.docker.com/build/buildkit/ |
| 67 | +[Dockerfiles]: https://docs.docker.com/reference/dockerfile/ |
| 68 | +[buildkit-installation]: https://github.com/moby/buildkit |
| 69 | +[container-engine]: |
| 70 | + https://developers.redhat.com/blog/2018/02/22/container-terminology-practical-introduction#h.6yt1ex5wfo3l |
| 71 | +[docker]: https://www.docker.com/ |
| 72 | +[podman]: https://docs.podman.io/en/latest/ |
| 73 | +[containerd]: https://containerd.io/ |
0 commit comments