2016-06-17 19:51:17 -04:00
# service ls
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_START -->
2016-06-17 19:51:17 -04:00
List services
2023-01-06 13:04:05 -05:00
### Aliases
`docker service ls` , `docker service 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-17 19:51:17 -04:00
2017-02-07 18:42:48 -05:00
## Description
2023-12-13 18:06:16 -05:00
This command lists services that are running in the swarm.
2018-12-23 06:27:52 -05:00
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.
2016-06-17 19:51:17 -04:00
2017-02-07 18:42:48 -05:00
## Examples
2016-06-17 19:51:17 -04:00
On a manager node:
2017-02-07 18:42:48 -05:00
2021-08-21 08:54:14 -04:00
```console
2016-10-24 23:39:53 -04:00
$ docker service ls
2017-02-07 18:42:48 -05:00
2020-01-09 13:17:43 -05:00
ID NAME MODE REPLICAS IMAGE
c8wgl7q4ndfd frontend replicated 5/5 nginx:alpine
2024-11-05 05:20:17 -05:00
dmu1ept4cxcf redis replicated 3/3 redis:7.4.1
2020-01-09 13:17:43 -05:00
iwe3278osahj mongo global 7/7 mongo:3.3
2021-03-11 09:36:02 -05:00
hh08h9uu8uwr job replicated-job 1/1 (3/5 completed) nginx:latest
2016-06-17 19:51:17 -04:00
```
2023-12-13 18:06:16 -05:00
The `REPLICAS` column shows both the actual and desired number of tasks for
2020-01-09 13:17:43 -05:00
the service. If the service is in `replicated-job` or `global-job` , it will
additionally show the completion status of the job as completed tasks over
total tasks the job will execute.
2016-06-17 19:51:17 -04:00
2023-01-06 13:28:29 -05:00
### <a name="filter"></a> Filtering (--filter)
2016-06-17 19:51:17 -04:00
The filtering flag (`-f` or `--filter` ) format is of "key=value". If there is more
2023-12-13 18:06:16 -05:00
than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"` ).
2016-06-17 19:51:17 -04:00
The currently supported filters are:
2016-11-08 23:06:00 -05:00
* [id ](service_ls.md#id )
* [label ](service_ls.md#label )
2017-03-03 17:08:49 -05:00
* [mode ](service_ls.md#mode )
2016-11-08 23:06:00 -05:00
* [name ](service_ls.md#name )
2016-06-17 19:51:17 -04:00
2017-02-07 18:42:48 -05:00
#### id
2016-06-17 19:51:17 -04:00
2018-10-16 03:56:29 -04:00
The `id` filter matches all or the prefix of a service's ID.
The following filter matches services with an ID starting with `0bcjw` :
2016-06-17 19:51:17 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-06-17 19:51:17 -04:00
$ docker service ls -f "id=0bcjw"
2016-10-24 23:39:53 -04:00
ID NAME MODE REPLICAS IMAGE
2024-11-05 05:20:17 -05:00
0bcjwfh8ychr redis replicated 1/1 redis:7.4.1
2016-06-17 19:51:17 -04:00
```
2017-02-07 18:42:48 -05:00
#### label
2016-06-17 19:51:17 -04:00
The `label` filter matches services based on the presence of a `label` alone or
a `label` and a value.
The following filter matches all services with a `project` label regardless of
its value:
2021-08-21 08:54:14 -04:00
```console
2016-06-17 19:51:17 -04:00
$ docker service ls --filter label=project
2016-10-24 23:39:53 -04:00
ID NAME MODE REPLICAS IMAGE
01sl1rp6nj5u frontend2 replicated 1/1 nginx:alpine
36xvvwwauej0 frontend replicated 5/5 nginx:alpine
2024-11-05 05:20:17 -05:00
74nzcxxjv6fq backend replicated 3/3 redis:7.4.1
2016-06-17 19:51:17 -04:00
```
The following filter matches only services with the `project` label with the
`project-a` value.
2021-08-21 08:54:14 -04:00
```console
2016-06-17 19:51:17 -04:00
$ docker service ls --filter label=project=project-a
2016-10-24 23:39:53 -04:00
ID NAME MODE REPLICAS IMAGE
36xvvwwauej0 frontend replicated 5/5 nginx:alpine
2024-11-05 05:20:17 -05:00
74nzcxxjv6fq backend replicated 3/3 redis:7.4.1
2016-06-17 19:51:17 -04:00
```
2017-03-03 17:08:49 -05:00
#### mode
The `mode` filter matches on the mode (either `replicated` or `global` ) of a service.
The following filter matches only `global` services.
2021-08-21 08:54:14 -04:00
```console
2017-03-03 17:08:49 -05:00
$ docker service ls --filter mode=global
ID NAME MODE REPLICAS IMAGE
w7y0v2yrn620 top global 1/1 busybox
```
2017-02-07 18:42:48 -05:00
#### name
2016-06-17 19:51:17 -04:00
2018-10-16 03:56:29 -04:00
The `name` filter matches on all or the prefix of a service's name.
2016-06-17 19:51:17 -04:00
2018-10-16 03:56:29 -04:00
The following filter matches services with a name starting with `redis` .
2016-06-17 19:51:17 -04:00
2021-08-21 08:54:14 -04:00
```console
2016-06-17 19:51:17 -04:00
$ docker service ls --filter name=redis
2016-10-24 23:39:53 -04:00
ID NAME MODE REPLICAS IMAGE
2024-11-05 05:20:17 -05:00
0bcjwfh8ychr redis replicated 1/1 redis:7.4.1
2016-06-17 19:51:17 -04:00
```
2023-01-06 13:28:29 -05: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 |
| `.Ports` | Service ports published in ingress mode |
2017-01-26 16:08:07 -05:00
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
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 service ls --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 service ls --format json
{"ID":"ssniordqolsi","Image":"hello-world:latest","Mode":"replicated","Name":"hello","Ports":"","Replicas":"0/1"}
```
2017-02-07 18:42:48 -05:00
## Related commands
2016-06-17 19:51:17 -04:00
* [service create ](service_create.md )
* [service inspect ](service_inspect.md )
2016-12-14 06:30:09 -05:00
* [service logs ](service_logs.md )
2017-07-20 04:32:51 -04:00
* [service ps ](service_ps.md )
2016-06-17 19:51:17 -04:00
* [service rm ](service_rm.md )
2017-07-20 04:32:51 -04:00
* [service rollback ](service_rollback.md )
2016-06-17 19:51:17 -04:00
* [service scale ](service_scale.md )
* [service update ](service_update.md )