build(guide): use c8d instead of docker-container driver

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2024-02-08 14:35:15 +01:00
parent bd4f1b99d1
commit 30b34b217b
2 changed files with 40 additions and 54 deletions

View File

@ -21,70 +21,58 @@ $ docker build --target=server --platform=linux/arm/v7 .
``` ```
You can also use emulation to produce outputs for multiple platforms at once. You can also use emulation to produce outputs for multiple platforms at once.
However, the default build driver doesn't support concurrent multi-platform However, the default image store in Docker Engine doesn't support building
builds. So first, you need to switch to a different builder, that uses a driver and loading multi-platform images. You need to enable the containerd image store
which supports concurrent multi-platform builds. which supports concurrent multi-platform builds.
To switch to using a different driver, you're going to need to use the Docker ## Enable the containerd image store
Buildx. Buildx is the next generation build client, and it provides a similar
user experience to the regular `docker build` command that youre used to, while
supporting additional features.
## Buildx setup {{< tabs >}}
{{< tab name="Docker Desktop" >}}
Buildx comes pre-bundled with Docker Desktop, and you can invoke this build To enable the containerd image store in Docker Desktop,
client using the `docker buildx` command. No need for any additional setup. If go to **Settings** and select **Use containerd for pulling and storing images**
you installed Docker Engine manually, you may need to install the Buildx plugin in the **General** tab.
separately. See
[Install Docker Engine](../../engine/install/index.md) for instructions.
Verify that the Buildx client is installed on your system, and that youre able Note that changing the image store means you'll temporarily lose access to
to run it: images and containers in the classic image store.
Those resources still exist, but to view them, you'll need to
disable the containerd image store.
```console {{< /tab >}}
$ docker buildx version {{< tab name="Docker Engine" >}}
github.com/docker/buildx v0.10.3 79e156beb11f697f06ac67fa1fb958e4762c0fab
If you're not using Docker Desktop,
enable the containerd image store by adding the following feature configuration
to your `/etc/docker/daemon.json` configuration file.
```json {hl_lines=3}
{
"features": {
"containerd-snapshotters": true
}
}
``` ```
Next, create a builder that uses the `docker-container`. Run the following Restart the daemon after updating the configuration file.
`docker buildx create` command:
```console ```console
$ docker buildx create --driver=docker-container --name=container $ systemctl restart docker
``` ```
This creates a new builder with the name `container`. You can list available {{< /tab >}}
builders with `docker buildx ls`. {{< /tabs >}}
```console
$ docker buildx ls
NAME/NODE DRIVER/ENDPOINT STATUS
container docker-container
container_0 unix:///var/run/docker.sock inactive
default * docker
default default running
desktop-linux docker
desktop-linux desktop-linux running
```
The status for the new `container` builder is inactive. That's fine - it's
because you haven't started using it yet.
## Build using emulation ## Build using emulation
To run multi-platform builds with Buildx, invoke the `docker buildx build` To run multi-platform builds, invoke the `docker build` command,
command, and pass it the same arguments as you did to the regular `docker build` and pass it the same arguments as you did before.
command before. Only this time, also add: Only this time, also add a `--platform` flag specifying multiple architectures.
- `--builder=container` to select the new builder ```console {hl_lines=4}
- `--platform=linux/amd64,linux/arm/v7,linux/arm64/v8` to build for multiple $ docker build \
architectures at once
```console
$ docker buildx build \
--target=binaries \ --target=binaries \
--output=bin \ --output=bin \
--builder=container \
--platform=linux/amd64,linux/arm64,linux/arm/v7 . --platform=linux/amd64,linux/arm64,linux/arm/v7 .
``` ```
@ -104,8 +92,8 @@ bin
└── server └── server
``` ```
When you build using a builder that supports multi-platform builds, the builder When you build for multiple platforms concurrently,
runs all of the build steps under emulation for each platform that you specify. BuildKit runs all of the build steps under emulation for each platform that you specify.
Effectively forking the build into two concurrent processes. Effectively forking the build into two concurrent processes.
![Build pipelines using emulation](./images/emulation.png) ![Build pipelines using emulation](./images/emulation.png)
@ -222,10 +210,9 @@ illustrates how to build, and export, binaries for Mac (ARM64), Windows, and
Linux: Linux:
```console ```console
$ docker buildx build \ $ docker build \
--target=binaries \ --target=binaries \
--output=bin \ --output=bin \
--builder=container \
--platform=darwin/arm64,windows/amd64,linux/amd64 . --platform=darwin/arm64,windows/amd64,linux/amd64 .
``` ```
@ -253,9 +240,8 @@ using emulation and cross-compilation.
Related information: Related information:
- [Multi-platfom images](../building/multi-platform.md) - [Multi-platfom images](../building/multi-platform.md)
- [Drivers overview](../drivers/index.md) - [containerd image store (Docker Desktop)](../../desktop/containerd.md)
- [Docker container driver](../drivers/docker-container.md) - [containerd image store (Docker Engine)](../../storage/containerd.md)
- [`docker buildx create` CLI reference](../../engine/reference/commandline/buildx_create.md)
You may also want to consider checking out You may also want to consider checking out
[xx - Dockerfile cross-compilation helpers](https://github.com/tonistiigi/xx). [xx - Dockerfile cross-compilation helpers](https://github.com/tonistiigi/xx).

View File

@ -31,4 +31,4 @@ extension or ad blocker, if you use one.
You can also submit an issue on You can also submit an issue on
[the docs GitHub repository](https://github.com/docker/docs/issues/new), [the docs GitHub repository](https://github.com/docker/docs/issues/new),
if you prefer. if you prefer.