2016-06-13 22:57:19 -04:00
# node ls
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_START -->
2016-07-07 14:43:18 -04:00
List nodes in the swarm
2016-06-13 22:57:19 -04:00
2023-01-06 13:04:05 -05:00
### Aliases
`docker node ls` , `docker node list`
### Options
| Name | Type | Default | Description |
|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`-f` ](#filter ), [`--filter` ](#filter ) | `filter` | | Filter output based on conditions provided |
| [`--format` ](#format ) | `string` | | Format output using a custom template:< br > 'table': Print output in table format with column headers (default)< br > 'table TEMPLATE': Print output in table format using the given Go template< br > 'json': Print in JSON format< br > 'TEMPLATE': Print output using the given Go template.< br > Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
2024-07-03 02:29:57 -04:00
| `-q` , `--quiet` | `bool` | | Only display IDs |
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_END -->
2016-06-13 22:57:19 -04:00
2017-02-07 18:42:48 -05:00
## Description
2016-06-13 22:57:19 -04:00
2017-02-07 18:42:48 -05:00
Lists all the nodes that the Docker Swarm manager knows about. You can filter
2023-01-06 12:05:02 -05:00
using the `-f` or `--filter` flag. Refer to the [filtering ](#filter ) section
2017-02-07 18:42:48 -05:00
for more information about available filter options.
2024-08-16 05:02:10 -04:00
> [!NOTE]
2020-04-19 11:08:37 -04:00
> This is a cluster management command, and must be executed on a swarm
> manager node. To learn about managers and workers, refer to the
> [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
> documentation.
2018-12-23 06:27:52 -05:00
2017-02-07 18:42:48 -05:00
## Examples
2016-06-13 22:57:19 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-07-22 07:13:30 -04:00
$ docker node ls
2016-06-13 22:57:19 -04:00
2016-07-22 07:13:30 -04:00
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active
38ciaotwjuritcdtn9npbnkuz swarm-worker1 Ready Active
e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader
```
2021-08-21 08:54:14 -04:00
2024-08-16 05:02:10 -04:00
> [!NOTE]
2020-04-19 11:08:37 -04:00
> In the above example output, there is a hidden column of `.Self` that indicates
> if the node is the same node as the current docker daemon. A `*` (e.g.,
> `e216jshn25ckzbvmwlnh5jr3g *`) means this node is the current docker daemon.
2017-01-24 16:17:40 -05:00
2016-06-13 22:57:19 -04:00
2023-01-06 13:28:29 -05:00
### <a name="filter"></a> Filtering (--filter)
2016-06-13 22:57:19 -04:00
The filtering flag (`-f` or `--filter` ) format is of "key=value". If there is more
than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"` )
The currently supported filters are:
2020-04-19 09:43:08 -04:00
* [id ](#id )
* [label ](#label )
2021-01-26 12:54:51 -05:00
* [node.label ](#nodelabel )
2020-04-19 09:43:08 -04:00
* [membership ](#membership )
* [name ](#name )
* [role ](#role )
2016-06-13 22:57:19 -04:00
2017-02-07 18:42:48 -05:00
#### id
2016-06-13 22:57:19 -04:00
2016-11-08 23:06:00 -05:00
The `id` filter matches all or part of a node's id.
2016-06-13 22:57:19 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-11-08 23:06:00 -05:00
$ docker node ls -f id=1
2016-07-22 07:13:30 -04:00
2016-11-08 23:06:00 -05:00
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active
2016-07-22 07:13:30 -04:00
```
2016-06-13 22:57:19 -04:00
2017-02-07 18:42:48 -05:00
#### label
2016-06-13 22:57:19 -04:00
2021-01-26 12:54:51 -05:00
The `label` filter matches nodes based on engine labels and on the presence of a
`label` alone or a `label` and a value. Engine labels are configured in
2024-02-13 07:40:53 -05:00
the [daemon configuration ](https://docs.docker.com/reference/cli/dockerd/#daemon-configuration-file ). To filter on
2021-01-26 12:54:51 -05:00
Swarm `node` labels, use [`node.label` instead ](#nodelabel ).
2016-11-08 23:06:00 -05:00
The following filter matches nodes with the `foo` label regardless of its value.
2016-06-13 22:57:19 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-11-08 23:06:00 -05:00
$ docker node ls -f "label=foo"
2016-06-13 22:57:19 -04:00
2016-07-22 07:13:30 -04:00
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active
```
2016-06-13 22:57:19 -04:00
2021-01-26 12:54:51 -05:00
#### node.label
The `node.label` filter matches nodes based on node labels and on the presence
of a `node.label` alone or a `node.label` and a value.
The following filter updates nodes to have a `region` node label:
```console
$ docker node update --label-add region=region-a swarm-test-01
$ docker node update --label-add region=region-a swarm-test-02
$ docker node update --label-add region=region-b swarm-test-03
$ docker node update --label-add region=region-b swarm-test-04
```
Show all nodes that have a `region` node label set:
```console
$ docker node ls --filter node.label=region
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
2023-04-10 08:14:29 -04:00
yg550ettvsjn6g6t840iaiwgb * swarm-test-01 Ready Active Leader 23.0.3
2lm9w9kbepgvkzkkeyku40e65 swarm-test-02 Ready Active Reachable 23.0.3
hc0pu7ntc7s4uvj4pv7z7pz15 swarm-test-03 Ready Active Reachable 23.0.3
n41b2cijmhifxxvz56vwrs12q swarm-test-04 Ready Active 23.0.3
2021-01-26 12:54:51 -05:00
```
Show all nodes that have a `region` node label, with value `region-a` :
```console
$ docker node ls --filter node.label=region=region-a
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
2023-04-10 08:14:29 -04:00
yg550ettvsjn6g6t840iaiwgb * swarm-test-01 Ready Active Leader 23.0.3
2lm9w9kbepgvkzkkeyku40e65 swarm-test-02 Ready Active Reachable 23.0.3
2021-01-26 12:54:51 -05:00
```
2017-04-24 08:53:30 -04:00
#### membership
2016-06-13 22:57:19 -04:00
2016-11-08 23:06:00 -05:00
The `membership` filter matches nodes based on the presence of a `membership` and a value
`accepted` or `pending` .
2016-06-13 22:57:19 -04:00
2016-11-08 23:06:00 -05:00
The following filter matches nodes with the `membership` of `accepted` .
2016-06-13 22:57:19 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-11-08 23:06:00 -05:00
$ docker node ls -f "membership=accepted"
2016-07-22 07:13:30 -04:00
2016-11-08 23:06:00 -05:00
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
1bcef6utixb0l0ca7gxuivsj0 swarm-worker2 Ready Active
38ciaotwjuritcdtn9npbnkuz swarm-worker1 Ready Active
2016-06-13 22:57:19 -04:00
```
2017-02-07 18:42:48 -05:00
#### name
2016-11-08 23:06:00 -05:00
The `name` filter matches on all or part of a node hostname.
The following filter matches the nodes with a name equal to `swarm-master` string.
2021-08-21 08:54:14 -04:00
```console
2016-11-08 23:06:00 -05:00
$ docker node ls -f name=swarm-manager1
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader
```
2017-02-07 18:42:48 -05:00
#### role
2016-11-08 23:06:00 -05:00
The `role` filter matches nodes based on the presence of a `role` and a value `worker` or `manager` .
The following filter matches nodes with the `manager` role.
2021-08-21 08:54:14 -04:00
```console
2016-11-08 23:06:00 -05:00
$ docker node ls -f "role=manager"
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader
```
2016-06-13 22:57:19 -04:00
2023-01-06 13:28:29 -05:00
### <a name="format"></a> Format the output (--format)
2017-01-24 16:17:40 -05:00
The formatting options (`--format`) pretty-prints nodes output
using a Go template.
Valid placeholders for the Go template are listed below:
2022-03-30 08:33:44 -04:00
| Placeholder | Description |
|------------------|-------------------------------------------------------------------------------------------------------|
| `.ID` | Node ID |
| `.Self` | Node of the daemon (`true/false`, `true` indicates that the node is the same as current docker daemon) |
| `.Hostname` | Node hostname |
| `.Status` | Node status |
| `.Availability` | Node availability ("active", "pause", or "drain") |
| `.ManagerStatus` | Manager status of the node |
| `.TLSStatus` | TLS status of the node ("Ready", or "Needs Rotation" has TLS certificate signed by an old CA) |
| `.EngineVersion` | Engine version |
2017-01-24 16:17:40 -05:00
When using the `--format` option, the `node ls` command will either
output the data exactly as the template declares or, when using the
`table` directive, includes column headers as well.
The following example uses a template without headers and outputs the
2020-04-19 11:23:09 -04:00
`ID` , `Hostname` , and `TLS Status` entries separated by a colon (`:`) for all
nodes:
2017-01-24 16:17:40 -05:00
2021-08-21 08:54:14 -04:00
```console
2017-05-10 16:32:47 -04:00
$ docker node ls --format "{{.ID}}: {{.Hostname}} {{.TLSStatus}}"
2021-08-21 08:54:14 -04:00
2017-05-10 16:32:47 -04:00
e216jshn25ckzbvmwlnh5jr3g: swarm-manager1 Ready
2020-03-15 10:11:43 -04:00
35o6tiywb700jesrt3dmllaza: swarm-worker1 Needs Rotation
2017-08-01 00:33:07 -04:00
```
2017-01-24 16:17:40 -05:00
2021-03-09 18:49:33 -05:00
To list all nodes in JSON format, use the `json` directive:
```console
$ docker node ls --format json
2023-04-10 08:14:29 -04:00
{"Availability":"Active","EngineVersion":"23.0.3","Hostname":"docker-desktop","ID":"k8f4w7qtzpj5sqzclcqafw35g","ManagerStatus":"Leader","Self":true,"Status":"Ready","TLSStatus":"Ready"}
2021-03-09 18:49:33 -05:00
```
2017-01-24 16:17:40 -05:00
2017-02-07 18:42:48 -05:00
## Related commands
2016-06-13 22:57:19 -04:00
2016-12-13 09:15:08 -05:00
* [node demote ](node_demote.md )
2016-06-13 22:57:19 -04:00
* [node inspect ](node_inspect.md )
2016-12-13 09:15:08 -05:00
* [node promote ](node_promote.md )
2016-07-19 17:01:31 -04:00
* [node ps ](node_ps.md )
2016-06-13 22:57:19 -04:00
* [node rm ](node_rm.md )
2016-12-13 09:15:08 -05:00
* [node update ](node_update.md )