Docker builders
The Buildx builders objects.
Don't use the constructor directly. Instead use
from python_on_whales import docker
my_builder = docker.buildx.inspect("my-builder")
# or
my_builder = docker.buildx.create()
For type hints, use this
from python_on_whales import Builder
Attributes
It attributes are the same that you get with the command line:
docker buildx inspect ...
Only a few are available at the moment
In [1]: from python_on_whales import docker
In [2]: my_builder = docker.buildx.create()
In [4]: def super_print(obj):
...: print(f"type={type(obj)}, value={obj}")
...:
In [4]: super_print(builder.name)
type = <class 'str'>, value = condescending_nightingale
In [5]: super_print(builder.driver)
type = <class 'str'>, value = docker-container
In [6]: super_print(builder.last_activity)
type = <class 'datetime.datetime'>, value = 2025-03-27 11:16:48+00:00
In [7]: super_print(builder.dynamic)
type = <class 'bool'>, value = False
In [8]: super_print(builder.nodes[0].name)
type = <class 'str'>, value = condescending_nightingale0
In [9]: super_print(builder.nodes[0].endpoint)
type = <class 'str'>, value = unix:///var/run/docker.sock
In [10]: super_print(builder.nodes[0].flags)
type = <class 'list'>, value = ['--allow-insecure-entitlement=network.host']
In [11]: super_print(builder.nodes[0].status)
type = <class 'str'>, value = inactive
In [12]: super_print(builder.nodes[0].version)
type = <class 'NoneType'>, value = None
In [13]: super_print(builder.nodes[0].ids)
type = <class 'NoneType'>, value = None
In [14]: super_print(builder.nodes[0].platforms)
type = <class 'NoneType'>, value = None
In [15]: super_print(builder.nodes[0].labels)
type = <class 'NoneType'>, value = None
Methods
Builder
remove
remove()
Removes this builder. After this operation the builder cannot be used anymore.
If you use the builder as a context manager, it will call this function when you exit the context manager.
from python_on_whales import docker
buildx_builder = docker.buildx.create(use=True)
with buildx_builder:
docker.build(".")
# now the variable buildx_builder is not usable since we're out of the context manager.
# the .remove() method was called behind the scenes
# since it was the current builder, 'default' is now the current builder.