Docker nodes
Nodes in Docker swarm
Don't use the constructor directly. Instead use
from python_on_whales import docker
my_docker_image = docker.node.inspect("my-node-name")
list_of_nodes = docker.node.list()
For type hints, use this
from python_on_whales import Node
def print_state(node: Node):
print(node.status.state)
Attributes
It attributes are the same that you get with the command line:
docker node 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]: docker.swarm.init()
In [3]: docker.node.list()[0]
In [4]: def super_print(obj):
...: print(f"type = {type(obj)}, value = {obj}")
...:
In [4]: super_print(node.id)
type = <class 'str'>, value = hy2qp8ys1lrmhi9mt00xa7qvr
In [5]: super_print(node.version.index)
type = <class 'int'>, value = 9
In [6]: super_print(node.created_at)
type = <class 'datetime.datetime'>, value = 2025-03-27 11:16:48.369335+00:00
In [7]: super_print(node.updated_at)
type = <class 'datetime.datetime'>, value = 2025-03-27 11:16:48.878723+00:00
In [8]: super_print(node.spec.name)
type = <class 'NoneType'>, value = None
In [9]: super_print(node.spec.labels)
type = <class 'dict'>, value = {}
In [10]: super_print(node.spec.role)
type = <class 'str'>, value = manager
In [11]: super_print(node.spec.availability)
type = <class 'str'>, value = active
In [12]: super_print(node.description.hostname)
type = <class 'str'>, value = fv-az1112-936
In [13]: super_print(node.description.platform.architecture)
type = <class 'str'>, value = x86_64
In [14]: super_print(node.description.platform.os)
type = <class 'str'>, value = linux
In [15]: super_print(node.description.resources.nano_cpus)
type = <class 'int'>, value = 4000000000
In [16]: super_print(node.description.resources.memory_bytes)
type = <class 'int'>, value = 16766763008
In [17]: super_print(node.description.resources.generic_resources)
type = <class 'NoneType'>, value = None
In [18]: super_print(node.description.engine.engine_version)
type = <class 'str'>, value = 26.1.3
In [19]: super_print(node.description.engine.labels)
type = <class 'NoneType'>, value = None
In [20]: super_print(node.description.engine.plugins)
type = <class 'list'>, value = [EnginePlugin(type='Log', name='awslogs'), EnginePlugin(type='Log', name='fluentd'), EnginePlugin(type='Log', name='gcplogs'), EnginePlugin(type='Log', name='gelf'), EnginePlugin(type='Log', name='journald'), EnginePlugin(type='Log', name='json-file'), EnginePlugin(type='Log', name='local'), EnginePlugin(type='Log', name='splunk'), EnginePlugin(type='Log', name='syslog'), EnginePlugin(type='Network', name='bridge'), EnginePlugin(type='Network', name='host'), EnginePlugin(type='Network', name='ipvlan'), EnginePlugin(type='Network', name='macvlan'), EnginePlugin(type='Network', name='null'), EnginePlugin(type='Network', name='overlay'), EnginePlugin(type='Volume', name='local'), EnginePlugin(type='Volume', name='mochoa/s3fs-volume-plugin:latest')]
In [21]: super_print(node.description.tls_info.trust_root)
type = <class 'str'>, value = -----BEGIN CERTIFICATE-----
MIIBazCCARCgAwIBAgIUfQcWhllURWZS9hd/ZTxcBuAJgz0wCgYIKoZIzj0EAwIw
EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjUwMzI3MTExMjAwWhcNNDUwMzIyMTEx
MjAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABN4McIPwfLMj/VKOQIAKWTKLTe2Ao0kw1vHD6CD0KoLyBigoiItD2BJ1yWBT
zqXOfbsaqiGtkyZz0MOMD3Y6E7yjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBTHiTUy4SYKtYpRR+fjcN9PfVsaujAKBggqhkjO
PQQDAgNJADBGAiEAuoV/jW6PeHNpjC2sxJRf9Efmc4tAUi4gCYDbk4+25TUCIQCE
GF2nOlLc/QTQZpS2zLm8RaPJSGhbAQ7fieJyz0qO3A==
-----END CERTIFICATE-----
In [22]: super_print(node.description.tls_info.cert_issuer_subject)
type = <class 'str'>, value = MBMxETAPBgNVBAMTCHN3YXJtLWNh
In [23]: super_print(node.description.tls_info.cert_issuer_public_key)
type = <class 'str'>, value = MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE3gxwg/B8syP9Uo5AgApZMotN7YCjSTDW8cPoIPQqgvIGKCiIi0PYEnXJYFPOpc59uxqqIa2TJnPQw4wPdjoTvA==
In [24]: super_print(node.status.state)
type = <class 'str'>, value = ready
In [25]: super_print(node.status.message)
type = <class 'NoneType'>, value = None
In [26]: super_print(node.status.addr)
type = <class 'str'>, value = 10.1.0.64
In [27]: super_print(node.manager_status.leader)
type = <class 'bool'>, value = True
In [28]: super_print(node.manager_status.reachability)
type = <class 'str'>, value = reachable
In [29]: super_print(node.manager_status.addr)
type = <class 'str'>, value = 10.1.0.64:2377
Methods
Node
ps
ps()
Returns the list of tasks running on this node
Returns
A `List[python_on_whales.Task]` object.
update
update(availability=None, labels_add={}, rm_labels=[], role=None)
Updates this Swarm node.
See docker.node.update
for more information
about the arguments.