If you create a docker-container or kubernetes builder with Buildx, you can
apply a custom BuildKit configuration by passing the
--buildkitd-config flag
to the docker buildx create command.
Registry mirror
You can define a registry mirror to use for your builds. Doing so redirects
BuildKit to pull images from a different hostname. The following steps exemplify
defining a mirror for docker.io (Docker Hub) to mirror.gcr.io.
Create a TOML at
/etc/buildkitd.tomlwith the following content:Notedebug = trueturns on debug requests in the BuildKit daemon, which logs a message that shows when a mirror is being used.Create a
docker-containerbuilder that uses this BuildKit configuration:Build an image:
The BuildKit logs for this builder now shows that it uses the GCR mirror. You
can tell by the fact that the response messages include the x-goog-* HTTP
headers.
Setting registry certificates
If you specify registry certificates in the BuildKit configuration, the daemon
copies the files into the container under /etc/buildkit/certs. The following
steps show adding a self-signed registry certificate to the BuildKit
configuration.
Add the following configuration to
/etc/buildkitd.toml:This tells the builder to push images to the
myregistry.comregistry using the certificates in the specified location (/etc/certs).Create a
docker-containerbuilder that uses this configuration:Inspect the builder's configuration file (
/etc/buildkit/buildkitd.toml), it shows that the certificate configuration is now configured in the builder.Verify that the certificates are inside the container:
Now you can push to the registry using this builder, and it will authenticate using the certificates:
CNI networking
CNI networking for builders can be useful for dealing with network port contention during concurrent builds. CNI is not yet available in the default BuildKit image. But you can create your own image that includes CNI support.
The following Dockerfile example shows a custom BuildKit image with CNI support. It uses the CNI config for integration tests in BuildKit as an example. Feel free to include your own CNI configuration.
Now you can build this image, and create a builder instance from it using
the --driver-opt image option:
Resource limiting
Max parallelism
You can limit the parallelism of the BuildKit solver, which is particularly useful
for low-powered machines, using a BuildKit configuration
while creating a builder with the
--buildkitd-config flag.
Now you can
create a docker-container builder
that will use this BuildKit configuration to limit parallelism.
TCP connection limit
TCP connections are limited to 4 simultaneous connections per registry for pulling and pushing images, plus one additional connection dedicated to metadata requests. This connection limit prevents your build from getting stuck while pulling images. The dedicated metadata connection helps reduce the overall build time.
More information: moby/buildkit#2259