@@ -27,15 +27,15 @@ production.
2727But containerization by itself only solves part of the problem. Containers
2828share the host kernel, which means that the code that's running inside the
2929container must be compatible with the host's architecture. This is why you
30- can't run a ` linux/amd64 ` container on a ` linux/ arm64` host, or a Windows
31- container on a Linux host.
30+ can't run a ` linux/amd64 ` container on an arm64 host (without using emulation),
31+ or a Windows container on a Linux host.
3232
3333Multi-platform builds solve this problem by packaging multiple variants of the
3434same application into a single image. This enables you to run the same image on
3535different types of hardware, such as development machines running x86-64 or
3636ARM-based Amazon EC2 instances in the cloud, without the need for emulation.
3737
38- {{< accordion title="How it works" >}}
38+ ### Difference between single-platform and multi-platform images
3939
4040Multi-platform images have a different structure than single-platform images.
4141Single-platform images contain a single manifest that points to a single
@@ -53,90 +53,71 @@ multi-platform image on an ARM-based Raspberry Pi, Docker selects the
5353` linux/arm64 ` variant. If you run the same image on an x86-64 laptop, Docker
5454selects the ` linux/amd64 ` variant (if you're using Linux containers).
5555
56- {{< /accordion >}}
57-
5856## Prerequisites
5957
60- To build multi-platform images, you first need to make sure that your builder
61- and Docker Engine support multi-platform builds. The easiest way to do this is
62- to [ enable the containerd image store] ( #enable-the-containerd-image-store ) .
58+ To build multi-platform images, you first need to make sure that your Docker
59+ environment is set up to support it. There are two ways you can do that:
6360
64- Alternatively, you can [ create a custom builder ] ( #create-a-custom-builder ) that
65- uses the ` docker-container ` driver, which supports multi-platform builds .
61+ - You can switch from the "classic" image store to the containerd image store.
62+ - You can create and use a custom builder .
6663
67- ### Enable the containerd image store
64+ The "classic" image store of the Docker Engine does not support multi-platform
65+ images. Switching to the containerd image store ensures that your Docker Engine
66+ can push, pull, and build multi-platform images.
6867
69- {{< tabs >}}
70- {{< tab name="Docker Desktop" >}}
68+ Creating a custom builder that uses the a driver with multi-platform support,
69+ such as the ` docker-container ` driver will let you build multi-platform images
70+ without switching to a different image store. However, you still won't be able
71+ to load the multi-platform images you build into your Docker Engine image
72+ store. But you can push them to a container registry directly with `docker
73+ build --push`.
7174
72- To enable the containerd image store in Docker Desktop,
73- go to ** Settings** and select ** Use containerd for pulling and storing images**
74- in the ** General** tab.
75+ {{< tabs >}}
76+ {{< tab name="containerd image store" >}}
7577
76- Note that changing the image store means you'll temporarily lose access to
77- images and containers in the classic image store.
78- Those resources still exist, but to view them, you'll need to
79- disable the containerd image store.
78+ The steps for enabling the containerd image store depends on whether you're
79+ using Docker Desktop or Docker Engine standalone:
8080
81- {{< /tab >}}
82- {{< tab name="Docker Engine" >}}
83-
84- If you're not using Docker Desktop,
85- enable the containerd image store by adding the following feature configuration
86- to your ` /etc/docker/daemon.json ` configuration file.
87-
88- ``` json {hl_lines=3}
89- {
90- "features" : {
91- "containerd-snapshotter" : true
92- }
93- }
94- ```
81+ - If you're using Docker Desktop, enable the containerd image store in the
82+ [ Docker Desktop settings] ( /manuals/desktop/containerd.md ) .
9583
96- Restart the daemon after updating the configuration file.
97-
98- ``` console
99- $ systemctl restart docker
100- ```
84+ - If you're using Docker Engine standalone, enable the containerd image store
85+ using the [ daemon configuration file] ( /manuals/engine/storage/containerd.md ) .
10186
10287{{< /tab >}}
103- {{< /tabs >}}
104-
105- ### Create a custom builder
88+ {{< tab name="Custom builder" >}}
10689
10790To create a custom builder, use the ` docker buildx create ` command to create a
108- builder that uses the ` docker-container ` driver. This driver runs the BuildKit
109- daemon in a container, as opposed to the default ` docker ` driver, which uses
110- the BuildKit library bundled with the Docker daemon. There isn't much
111- difference between the two drivers, but the ` docker-container ` driver provides
112- more flexibility and advanced features, including multi-platform support.
91+ builder that uses the ` docker-container ` driver.
11392
11493``` console
11594$ docker buildx create \
11695 --name container-builder \
11796 --driver docker-container \
118- --use --bootstrap
97+ --bootstrap --use
11998```
12099
121- This command creates a new builder named ` container-builder ` that uses the
122- ` docker-container ` driver (default) and sets it as the active builder. The
123- ` --bootstrap ` flag pulls the BuildKit image and starts the build container.
100+ > [ !NOTE]
101+ > Builds with the ` docker-container ` driver aren't automatically loaded to your
102+ > Docker Engine image store. For more information, see [ Build
103+ > drivers] ( /manuals/build/builders/drivers/_index.md ) .
104+
105+ {{< /tab >}}
106+ {{< /tabs >}}
107+
108+ If you're using Docker Engine standalone and you need to build multi-platform
109+ images using emulation, you also need to install QEMU, see [ Install QEMU
110+ manually] ( #install-qemu-manually ) .
124111
125112## Build multi-platform images
126113
127114When triggering a build, use the ` --platform ` flag to define the target
128115platforms for the build output, such as ` linux/amd64 ` and ` linux/arm64 ` :
129116
130117``` console
131- $ docker build --platform linux/amd64,linux/arm64 .
118+ $ docker buildx build --platform linux/amd64,linux/arm64 .
132119```
133120
134- > [ !NOTE]
135- > If you're using the ` docker-container ` driver, you need to specify the
136- > ` --load ` flag to load the image into the local image store after the build
137- > finishes. This is because images built using the ` docker-container ` driver
138- > aren't automatically loaded into the local image store.
139-
140121## Strategies
141122
142123You can build multi-platform images using three different strategies,
@@ -276,7 +257,7 @@ architecture of the container.
276257Prerequisites:
277258
278259- Docker Desktop, or Docker Engine with [ QEMU installed] ( #install-qemu-manually )
279- - [ containerd image store enabled] ( #enable-the-containerd-image-store )
260+ - containerd image store enabled
280261
281262Steps:
282263
0 commit comments