How to multiarch build images sequentially with docker buildx

1.4k Views Asked by At

When I want to create multiarch builds with docker, I use the command:

docker buildx build --push --platform <list of archs> -t <tag1> -t <tag2> .

This works perfectly fine, but seems to be building the images concurrently. In most situations, it may be acceptable, but in some other cases, this seems to be too heavy, requires too much RAM and causes network failures (too many parallel connections).

Is there any way to build the images sequentially?

The only solution I found is to build for each arch separately and then use "docker manifest create" to assemble:

docker buildx build --push --platform <arch1> -t <tag-arch1> .
docker buildx build --push --platform <arch2> -t <tag-arch2> .
[...]
docker manifest create ... --amend ...
docker manifest push

This may be fine, but it seems that each image is supposed to be pushed to the registry for "docker manifest create" to be able to assemble. This is not very good, as it pollutes the list of images of tags I don't want.

Would it be possible to use "docker manifest create" on local images, without the need to upload each of them separately with a tag to the registry? Is there any better way to simply build the images sequentially? Thanks!

1

There are 1 best solutions below

4
On BEST ANSWER

This can be done with a max-parallelism option in buildkit:

$ cat buildkitd.toml
[worker.oci]
  max-parallelism = 4

$ docker buildx create --use \
  --name container \
  --driver docker-container \
  --config buildkitd.toml

For more details, see: https://docs.docker.com/build/buildkit/configure/#max-parallelism

The tracking issue for this feature is buildkit #1131.