Skip to content

Docker configs

Configs objects present in Swarm mode

Don't use the constructor directly. Instead use

from python_on_whales import docker

my_config = docker.config.inspect("my-config-name")

# or

my_config = docker.config.create("my_config_name", "my_config_file")

For type hints, use this

from python_on_whales import Config

def print_config_labels(config: Config):
    print(config.spec.labels)

Attributes

It attributes are the same that you get with the command line: docker config inspect ...

To get a complete description of those attributes, you can take a look at the daemon api reference page and click on "200 No error".

An example is worth many lines of descriptions.

In [1]: from python_on_whales import docker

In [2]: config = docker.config.create("my_config", "./config_file.cfg", labels=dict(hello="world"))

In [3]: def super_print(obj):
   ...:     print(f"type={type(obj)}, value={obj}")
   ...:

In [4]: super_print(config.id)
type = <class 'str'>, value = 5p2vcdm7pt47g7uq5qm4fhick

In [5]: super_print(config.version.index)
type = <class 'int'>, value = 11

In [6]: super_print(config.created_at)
type = <class 'datetime.datetime'>, value = 2024-09-06 10:23:20.424889+00:00

In [7]: super_print(config.updated_at)
type = <class 'datetime.datetime'>, value = 2024-09-06 10:23:20.424889+00:00

In [8]: super_print(config.spec.name)
type = <class 'str'>, value = my_config

In [9]: super_print(config.spec.labels)
type = <class 'dict'>, value = {'hello': 'world'}

In [10]: super_print(config.spec.data)
type = <class 'str'>, value = SGVsbG8gd29ybGQh

In [11]: super_print(config.spec.templating)
type = <class 'NoneType'>, value = None

Methods

Config

remove

remove()

Remove this config.

Note that you can also use a python_on_whales.Config as a context manager to ensure it's removed even if an exception occurs.