Skip to content

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

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

In [6]: super_print(node.created_at)
type = <class 'datetime.datetime'>, value = 2024-04-24 08:10:33.617443+00:00

In [7]: super_print(node.updated_at)
type = <class 'datetime.datetime'>, value = 2024-04-24 08:10:34.221188+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-az770-462

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

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

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='logentries'), 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-----
MIIBajCCARCgAwIBAgIUBiBGOHokJBUUITS3R35cSHHfaEwwCgYIKoZIzj0EAwIw
EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjQwNDI0MDgwNjAwWhcNNDQwNDE5MDgw
NjAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABJEbplEfzzBZdmk7NyHkxsvJVr2OupgmX2adci4Yqv5IW2zNZ4Qmu1KVBzOS
twgNlPNjq3HpG3m3iHzXwZJXEsejQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBSsI7S0bPPht7jIB9sJg5ZzXEQ+QzAKBggqhkjO
PQQDAgNIADBFAiEAwY/9cBEBl2yf1uEaNQ6lbKGWT5e52pRbEPEG5yQVGqUCIEIG
WG4mO016+XVf3n+nKi7dRyzUdXSTF1scF85XeAp0
-----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 = MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEkRumUR/PMFl2aTs3IeTGy8lWvY66mCZfZp1yLhiq/khbbM1nhCa7UpUHM5K3CA2U82OrcekbebeIfNfBklcSxw==

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.58

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.58: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.