2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "stack services"
|
|
|
|
description: "The stack services command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "stack, services"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2016-07-20 12:54:48 -04:00
|
|
|
|
2018-06-22 02:16:27 -04:00
|
|
|
# stack services
|
2016-07-20 12:54:48 -04:00
|
|
|
|
|
|
|
```markdown
|
2020-10-02 09:51:01 -04:00
|
|
|
Usage: docker stack services [OPTIONS] STACK
|
2016-07-20 12:54:48 -04:00
|
|
|
|
|
|
|
List the services in the stack
|
|
|
|
|
|
|
|
Options:
|
2018-06-22 02:16:27 -04:00
|
|
|
-f, --filter filter Filter output based on conditions provided
|
2021-03-09 18:49:33 -05:00
|
|
|
--format string Format output using a custom template:
|
|
|
|
'table': Print output in table format with column headers (default)
|
|
|
|
'table TEMPLATE': Print output in table format using the given Go template
|
|
|
|
'json': Print in JSON format
|
|
|
|
'TEMPLATE': Print output using the given Go template.
|
|
|
|
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
|
2018-06-22 02:16:27 -04:00
|
|
|
--help Print usage
|
|
|
|
-q, --quiet Only display IDs
|
2016-07-20 12:54:48 -04:00
|
|
|
```
|
|
|
|
|
2017-03-12 15:01:06 -04:00
|
|
|
## Description
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2018-12-23 06:27:52 -05:00
|
|
|
Lists the services that are running as part of the specified stack.
|
|
|
|
|
2020-04-19 11:08:37 -04:00
|
|
|
> **Note**
|
|
|
|
>
|
|
|
|
> 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.
|
2016-07-20 12:54:48 -04:00
|
|
|
|
2017-03-12 15:01:06 -04:00
|
|
|
## Examples
|
2017-02-07 18:42:48 -05:00
|
|
|
|
|
|
|
The following command shows all services in the `myapp` stack:
|
2016-07-20 12:54:48 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-07-20 12:54:48 -04:00
|
|
|
$ docker stack services myapp
|
|
|
|
|
|
|
|
ID NAME REPLICAS IMAGE COMMAND
|
|
|
|
7be5ei6sqeye myapp_web 1/1 nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f
|
|
|
|
dn7m7nhhfb9y myapp_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
|
|
|
|
```
|
|
|
|
|
2022-03-30 09:05:29 -04:00
|
|
|
### <a name=filter></a> Filtering (--filter)
|
2016-07-20 12:54:48 -04:00
|
|
|
|
|
|
|
The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there
|
|
|
|
is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`).
|
2016-10-13 15:03:08 -04:00
|
|
|
Multiple filter flags are combined as an `OR` filter.
|
2016-07-20 12:54:48 -04:00
|
|
|
|
|
|
|
The following command shows both the `web` and `db` services:
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-07-20 12:54:48 -04:00
|
|
|
$ docker stack services --filter name=myapp_web --filter name=myapp_db myapp
|
|
|
|
|
|
|
|
ID NAME REPLICAS IMAGE COMMAND
|
|
|
|
7be5ei6sqeye myapp_web 1/1 nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f
|
|
|
|
dn7m7nhhfb9y myapp_db 1/1 mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
|
|
|
|
```
|
|
|
|
|
|
|
|
The currently supported filters are:
|
|
|
|
|
|
|
|
* id / ID (`--filter id=7be5ei6sqeye`, or `--filter ID=7be5ei6sqeye`)
|
|
|
|
* label (`--filter label=key=value`)
|
2018-04-24 06:28:08 -04:00
|
|
|
* mode (`--filter mode=replicated`, or `--filter mode=global`)
|
|
|
|
* Swarm: not supported
|
|
|
|
* name (`--filter name=myapp_web`)
|
|
|
|
* node (`--filter node=mynode`)
|
|
|
|
* Swarm: not supported
|
|
|
|
* service (`--filter service=web`)
|
|
|
|
* Swarm: not supported
|
2016-07-20 12:54:48 -04:00
|
|
|
|
2022-03-30 09:05:29 -04:00
|
|
|
### <a name=format></a> Format the output (--format)
|
2017-01-26 16:08:07 -05:00
|
|
|
|
|
|
|
The formatting options (`--format`) pretty-prints services 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` | Service ID |
|
|
|
|
| `.Name` | Service name |
|
|
|
|
| `.Mode` | Service mode (replicated, global) |
|
|
|
|
| `.Replicas` | Service replicas |
|
|
|
|
| `.Image` | Service image |
|
2017-01-26 16:08:07 -05:00
|
|
|
|
|
|
|
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
|
2020-04-19 11:23:09 -04:00
|
|
|
`ID`, `Mode`, and `Replicas` entries separated by a colon (`:`) for all services:
|
2017-01-26 16:08:07 -05:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2017-01-26 16:08:07 -05:00
|
|
|
$ docker stack services --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2017-01-26 16:08:07 -05:00
|
|
|
0zmvwuiu3vue: replicated 10/10
|
|
|
|
fm6uf97exkul: global 5/5
|
|
|
|
```
|
|
|
|
|
2021-03-09 18:49:33 -05:00
|
|
|
To list all services in JSON format, use the `json` directive:
|
2022-03-30 08:33:44 -04:00
|
|
|
|
2021-03-09 18:49:33 -05:00
|
|
|
```console
|
|
|
|
$ docker stack services ls --format json
|
|
|
|
{"ID":"0axqbl293vwm","Image":"localstack/localstack:latest","Mode":"replicated","Name":"myapp_localstack","Ports":"*:4566-\u003e4566/tcp, *:8080-\u003e8080/tcp","Replicas":"0/1"}
|
|
|
|
{"ID":"384xvtzigz3p","Image":"redis:6.0.9-alpine3.12","Mode":"replicated","Name":"myapp_redis","Ports":"*:6379-\u003e6379/tcp","Replicas":"1/1"}
|
|
|
|
{"ID":"hyujct8cnjkk","Image":"postgres:13.2-alpine","Mode":"replicated","Name":"myapp_repos-db","Ports":"*:5432-\u003e5432/tcp","Replicas":"0/1"}
|
|
|
|
```
|
|
|
|
|
2017-01-26 16:08:07 -05:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Related commands
|
2016-07-20 12:54:48 -04:00
|
|
|
|
|
|
|
* [stack deploy](stack_deploy.md)
|
2016-06-23 01:00:21 -04:00
|
|
|
* [stack ls](stack_ls.md)
|
2016-12-13 05:06:18 -05:00
|
|
|
* [stack ps](stack_ps.md)
|
|
|
|
* [stack rm](stack_rm.md)
|