8.4 KiB
buildx create
docker buildx create [OPTIONS] [CONTEXT|ENDPOINT]
Create a new builder instance
Options
| Name | Description |
|---|---|
--append |
Append a node to builder instead of changing it |
--bootstrap |
Boot builder after creation |
--buildkitd-flags string |
Flags for buildkitd daemon |
--config string |
BuildKit config file |
--driver string |
Driver to use (available: docker, docker-container, kubernetes) |
--driver-opt stringArray |
Options for the driver |
--leave |
Remove a node from builder instead of changing it |
--name string |
Builder instance name |
--node string |
Create/modify node with given name |
--platform stringArray |
Fixed platforms for current node |
--use |
Set the current builder instance |
Description
Create makes a new builder instance pointing to a docker context or endpoint,
where context is the name of a context from docker context ls and endpoint is
the address for docker socket (eg. DOCKER_HOST value).
By default, the current Docker configuration is used for determining the context/endpoint value.
Builder instances are isolated environments where builds can be invoked. All Docker contexts also get the default builder instance.
Examples
Append a new node to an existing builder (--append)
The --append flag changes the action of the command to append a new node to an
existing builder specified by --name. Buildx will choose an appropriate node
for a build based on the platforms it supports.
Examples
$ docker buildx create mycontext1
eager_beaver
$ docker buildx create --name eager_beaver --append mycontext2
eager_beaver
Specify options for the buildkitd daemon (--buildkitd-flags)
--buildkitd-flags FLAGS
Adds flags when starting the buildkitd daemon. They take precedence over the
configuration file specified by --config. See buildkitd --help
for the available flags.
Example
--buildkitd-flags '--debug --debugaddr 0.0.0.0:6666'
Specify a configuration file for the buildkitd daemon (--config)
--config FILE
Specifies the configuration file for the buildkitd daemon to use. The configuration
can be overridden by --buildkitd-flags.
See an example buildkitd configuration file.
Note that if you create a docker-container builder and have specified
certificates for registries in the buildkitd.toml configuration, the files
will be copied into the container under /etc/buildkit/certs and configuration
will be updated to reflect that.
Set the builder driver to use (--driver)
--driver DRIVER
Sets the builder driver to be used. There are two available drivers, each have their own specificities.
docker driver
Uses the builder that is built into the docker daemon. With this driver,
the --load flag is implied by default on
buildx build. However, building multi-platform images or exporting cache is
not currently supported.
docker-container driver
Uses a BuildKit container that will be spawned via docker. With this driver, both building multi-platform images and exporting cache are supported.
Unlike docker driver, built images will not automatically appear in
docker images and build --load needs to be used
to achieve that.
kubernetes driver
Uses a kubernetes pods. With this driver, you can spin up pods with defined BuildKit container image to build your images.
Unlike docker driver, built images will not automatically appear in
docker images and build --load needs to be used
to achieve that.
Set additional driver-specific options (--driver-opt)
--driver-opt OPTIONS
Passes additional driver-specific options. Details for each driver:
docker- No driver optionsdocker-containerimage=IMAGE- Sets the container image to be used for running buildkit.network=NETMODE- Sets the network mode for running the buildkit container.cgroup-parent=CGROUP- Sets the cgroup parent of the buildkit container if docker is using the "cgroupfs" driver. Defaults to/docker/buildx.
kubernetesimage=IMAGE- Sets the container image to be used for running buildkit.namespace=NS- Sets the Kubernetes namespace. Defaults to the current namespace.replicas=N- Sets the number ofPodreplicas. Defaults to 1.requests.cpu- Sets the request CPU value specified in units of Kubernetes CPU. Examplerequests.cpu=100m,requests.cpu=2requests.memory- Sets the request memory value specified in bytes or with a valid suffix. Examplerequests.memory=500Mi,requests.memory=4Glimits.cpu- Sets the limit CPU value specified in units of Kubernetes CPU. Examplelimits.cpu=100m,limits.cpu=2limits.memory- Sets the limit memory value specified in bytes or with a valid suffix. Examplelimits.memory=500Mi,limits.memory=4Gnodeselector="label1=value1,label2=value2"- Sets the kv ofPodnodeSelector. No Defaults. Examplenodeselector=kubernetes.io/arch=arm64rootless=(true|false)- Run the container as a non-root user withoutsecurityContext.privileged. Using Ubuntu host kernel is recommended. Defaults to false.loadbalance=(sticky|random)- Load-balancing strategy. If set to "sticky", the pod is chosen using the hash of the context path. Defaults to "sticky"qemu.install=(true|false)- Install QEMU emulation for multi platforms support.qemu.image=IMAGE- Sets the QEMU emulation image. Defaults totonistiigi/binfmt:latest
Examples
Use a custom network
$ docker network create foonet
$ docker buildx create --name builder --driver docker-container --driver-opt network=foonet --use
$ docker buildx inspect --bootstrap
$ docker inspect buildx_buildkit_builder0 --format={{.NetworkSettings.Networks}}
map[foonet:0xc00018c0c0]
OpenTelemetry support
To capture the trace to Jaeger, set
JAEGER_TRACE environment variable to the collection address using the driver-opt:
$ docker run -d --name jaeger -p 6831:6831/udp -p 16686:16686 jaegertracing/all-in-one
$ docker buildx create --name builder --driver docker-container --driver-opt network=host --driver-opt env.JAEGER_TRACE=localhost:6831 --use
$ docker buildx inspect --bootstrap
# buildx command should be traced at http://127.0.0.1:16686/
Remove a node from a builder (--leave)
The --leave flag changes the action of the command to remove a node from a
builder. The builder needs to be specified with --name and node that is removed
is set with --node.
Examples
$ docker buildx create --name mybuilder --node mybuilder0 --leave
Specify the name of the builder (--name)
--name NAME
The --name flag specifies the name of the builder to be created or modified.
If none is specified, one will be automatically generated.
Specify the name of the node (--node)
--node NODE
The --node flag specifies the name of the node to be created or modified. If
none is specified, it is the name of the builder it belongs to, with an index
number suffix.
Set the platforms supported by the node
--platform PLATFORMS
The --platform flag sets the platforms supported by the node. It expects a
comma-separated list of platforms of the form OS/architecture/variant. The node
will also automatically detect the platforms it supports, but manual values take
priority over the detected ones and can be used when multiple nodes support
building for the same platform.
Examples
$ docker buildx create --platform linux/amd64
$ docker buildx create --platform linux/arm64,linux/arm/v8
Automatically switch to the newly created builder
The --use flag automatically switches the current builder to the newly created
one. Equivalent to running docker buildx use $(docker buildx create ...).