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 = 1l8ksf3eny8j1nd31yup18nli

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-11-20 11:35:30.761490+00:00

In [7]: super_print(node.updated_at)
type = <class 'datetime.datetime'>, value = 2024-11-20 11:35:31.267335+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-az985-248

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

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-----
MIIBajCCARCgAwIBAgIURK2J1vzAf9B8juSYtdKoMDku2kQwCgYIKoZIzj0EAwIw
EzERMA8GA1UEAxMIc3dhcm0tY2EwHhcNMjQxMTIwMTEzMTAwWhcNNDQxMTE1MTEz
MTAwWjATMREwDwYDVQQDEwhzd2FybS1jYTBZMBMGByqGSM49AgEGCCqGSM49AwEH
A0IABDbqlgU44tpA4cOa6L4qUmYq8HbXgHjl6bYnRTl3xFoNkpggmh7gYTtGiX4H
pjkCn9q+LNak46BM4RFZwmKXC1WjQjBAMA4GA1UdDwEB/wQEAwIBBjAPBgNVHRMB
Af8EBTADAQH/MB0GA1UdDgQWBBR7/6mJlF/SsnseQhPVE664CH173TAKBggqhkjO
PQQDAgNIADBFAiB0PVUcNu8Kn9mUyWGuhsWZs2820aA9SsRXNRly9mDIDgIhAO/D
6MLK385dJoRYCOUzWi7ry9ZaR4XNUmGEenH9e2AU
-----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 = MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENuqWBTji2kDhw5rovipSZirwdteAeOXptidFOXfEWg2SmCCaHuBhO0aJfgemOQKf2r4s1qTjoEzhEVnCYpcLVQ==

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

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