Add --format for docker node ls
This fix tries to address the comment https://github.com/docker/docker/pull/30376#discussion_r97465334 where it was not possible to specify `--format` for `docker node ls`. The `--format` flag is a quite useful flag that could be used in many places such as completion. This fix implements `--format` for `docker node ls` and add `nodesFormat` in config.json so that it is possible to specify the output when `docker node ls` is invoked. Related documentations have been updated. A set of unit tests have been added. This fix is related to #30376. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
@ -24,9 +24,10 @@ Aliases:
|
||||
ls, list
|
||||
|
||||
Options:
|
||||
-f, --filter value Filter output based on conditions provided
|
||||
--help Print usage
|
||||
-q, --quiet Only display IDs
|
||||
-f, --filter filter Filter output based on conditions provided
|
||||
--format string Pretty-print nodes using a Go template
|
||||
--help Print usage
|
||||
-q, --quiet Only display IDs
|
||||
```
|
||||
|
||||
## Description
|
||||
@ -45,6 +46,10 @@ ID HOSTNAME STATUS AVAILABILITY MANAGER STATU
|
||||
38ciaotwjuritcdtn9npbnkuz swarm-worker1 Ready Active
|
||||
e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader
|
||||
```
|
||||
> **Note:**
|
||||
> If the `ID` field of the node is followed by a `*` (e.g., `e216jshn25ckzbvmwlnh5jr3g *`)
|
||||
> in the above example output, then this node is also the node of the current docker daemon.
|
||||
|
||||
|
||||
### Filtering
|
||||
|
||||
@ -124,6 +129,34 @@ ID HOSTNAME STATUS AVAILABILITY MANAGER STATU
|
||||
e216jshn25ckzbvmwlnh5jr3g * swarm-manager1 Ready Active Leader
|
||||
```
|
||||
|
||||
### Formatting
|
||||
|
||||
The formatting options (`--format`) pretty-prints nodes output
|
||||
using a Go template.
|
||||
|
||||
Valid placeholders for the Go template are listed below:
|
||||
|
||||
Placeholder | Description
|
||||
-----------------|------------------------------------------------------------------------------------------
|
||||
`.ID` | Node ID
|
||||
`.Hostname` | Node hostname
|
||||
`.Status` | Node status
|
||||
`.Availability` | Node availability ("active", "pause", or "drain")
|
||||
`.ManagerStatus` | Manager status of the node
|
||||
|
||||
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
|
||||
`ID` and `Hostname` entries separated by a colon for all nodes:
|
||||
|
||||
```bash
|
||||
$ docker node ls --format "{{.ID}}: {{.Hostname}}"
|
||||
e216jshn25ckzbvmwlnh5jr3g *: swarm-manager1
|
||||
``
|
||||
|
||||
|
||||
## Related commands
|
||||
|
||||
* [node demote](node_demote.md)
|
||||
|
||||
Reference in New Issue
Block a user