Configure BuildKit (original) (raw)
If you create a docker-container
or kubernetes
builder with Buildx, you can apply a customBuildKit configuration by passing the--config flag to the docker buildx create
command.
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.toml
with the following content:Note
debug = true
turns on debug requests in the BuildKit daemon, which logs a message that shows when a mirror is being used. - Create a
docker-container
builder 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.
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 themyregistry.com
registry using the certificates in the specified location (/etc/certs
). - Create a
docker-container
builder 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 for builders can be useful for dealing with network port contention during concurrent builds. CNI isnot yetavailable 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 theCNI config for integration testsin 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 usingthe --driver-opt image option:
Max parallelism
You can limit the parallelism of the BuildKit solver, which is particularly useful for low-powered machines, using aBuildKit configurationwhile creating a builder with the--config flags.
Now you cancreate a docker-container builderthat 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