Skip to content

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 = vigorous_hawking

In [5]: super_print(builder.driver)
type = <class 'str'>, value = docker-container

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.