Add --format to docker service ls

This fix tries to improve the display of `docker service ls`
and adds `--format` flag to `docker service ls`.

In addition to `--format` flag, several other improvement:
1. Updates `docker stacks service`.
2. Adds `servicesFormat` to config file.

Related docs has been updated.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2017-01-26 13:08:07 -08:00 committed by Tibor Vass
parent b8b156f343
commit 7d3b3fda0d
3 changed files with 73 additions and 6 deletions

View File

@ -137,6 +137,13 @@ Docker's client uses this property. If this property is not set, the client
falls back to the default table format. For a list of supported formatting
directives, see the [**Formatting** section in the `docker plugin ls` documentation](plugin_ls.md)
The property `servicesFormat` specifies the default format for `docker
service ls` output. When the `--format` flag is not provided with the
`docker service ls` command, Docker's client uses this property. If this
property is not set, the client falls back to the default json format. For a
list of supported formatting directives, see the
[**Formatting** section in the `docker service ls` documentation](service_ls.md)
The property `serviceInspectFormat` specifies the default format for `docker
service inspect` output. When the `--format` flag is not provided with the
`docker service inspect` command, Docker's client uses this property. If this
@ -194,6 +201,7 @@ Following is a sample `config.json` file:
"imagesFormat": "table {{.ID}}\\t{{.Repository}}\\t{{.Tag}}\\t{{.CreatedAt}}",
"pluginsFormat": "table {{.ID}}\t{{.Name}}\t{{.Enabled}}",
"statsFormat": "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}",
"servicesFormat": "table {{.ID}}\t{{.Name}}\t{{.Mode}}",
"serviceInspectFormat": "pretty",
"detachKeys": "ctrl-e,e",
"credsStore": "secretservice",

View File

@ -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 services using a Go template
--help Print usage
-q, --quiet Only display IDs
```
This command when run targeting a manager, lists services are running in the
@ -103,6 +104,34 @@ ID NAME MODE REPLICAS IMAGE
0bcjwfh8ychr redis replicated 1/1 redis:3.0.6
```
## Formatting
The formatting options (`--format`) pretty-prints services output
using a Go template.
Valid placeholders for the Go template are listed below:
Placeholder | Description
------------|------------------------------------------------------------------------------------------
`.ID` | Service ID
`.Name` | Service name
`.Mode` | Service mode (replicated, global)
`.Replicas` | Service replicas
`.Image` | Service image
When using the `--format` option, the `service 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`, `Mode`, and `Replicas` entries separated by a colon for all services:
```bash
$ docker service ls --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
0zmvwuiu3vue: replicated 10/10
fm6uf97exkul: global 5/5
```
## Related information
* [service create](service_create.md)

View File

@ -22,9 +22,10 @@ Usage: docker stack services [OPTIONS] STACK
List the services in the stack
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 services using a Go template
--help Print usage
-q, --quiet Only display IDs
```
Lists the services that are running as part of the specified stack. This
@ -62,6 +63,35 @@ The currently supported filters are:
* name (`--filter name=myapp_web`)
* label (`--filter label=key=value`)
## Formatting
The formatting options (`--format`) pretty-prints services output
using a Go template.
Valid placeholders for the Go template are listed below:
Placeholder | Description
------------|------------------------------------------------------------------------------------------
`.ID` | Service ID
`.Name` | Service name
`.Mode` | Service mode (replicated, global)
`.Replicas` | Service replicas
`.Image` | Service image
When using the `--format` option, the `stack services` 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`, `Mode`, and `Replicas` entries separated by a colon for all services:
```bash
$ docker stack services --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
0zmvwuiu3vue: replicated 10/10
fm6uf97exkul: global 5/5
```
## Related information
* [stack deploy](stack_deploy.md)