...

Text file src/github.com/docker/cli/docs/reference/commandline/service_ls.md

Documentation: github.com/docker/cli/docs/reference/commandline

     1# service ls
     2
     3<!---MARKER_GEN_START-->
     4List services
     5
     6### Aliases
     7
     8`docker service ls`, `docker service list`
     9
    10### Options
    11
    12| Name                                   | Type     | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                          |
    13|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
    14| [`-f`](#filter), [`--filter`](#filter) | `filter` |         | Filter output based on conditions provided                                                                                                                                                                                                                                                                                                                                                                                           |
    15| [`--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 |
    16| `-q`, `--quiet`                        |          |         | Only display IDs                                                                                                                                                                                                                                                                                                                                                                                                                     |
    17
    18
    19<!---MARKER_GEN_END-->
    20
    21## Description
    22
    23This command lists services that are running in the swarm.
    24
    25> **Note**
    26>
    27> This is a cluster management command, and must be executed on a swarm
    28> manager node. To learn about managers and workers, refer to the
    29> [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
    30> documentation.
    31
    32## Examples
    33
    34On a manager node:
    35
    36```console
    37$ docker service ls
    38
    39ID            NAME      MODE            REPLICAS             IMAGE
    40c8wgl7q4ndfd  frontend  replicated      5/5                  nginx:alpine
    41dmu1ept4cxcf  redis     replicated      3/3                  redis:3.0.6
    42iwe3278osahj  mongo     global          7/7                  mongo:3.3
    43hh08h9uu8uwr  job       replicated-job  1/1 (3/5 completed)  nginx:latest
    44```
    45
    46The `REPLICAS` column shows both the actual and desired number of tasks for
    47the service. If the service is in `replicated-job` or `global-job`, it will
    48additionally show the completion status of the job as completed tasks over
    49total tasks the job will execute.
    50
    51### <a name="filter"></a> Filtering (--filter)
    52
    53The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more
    54than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`).
    55
    56The currently supported filters are:
    57
    58* [id](service_ls.md#id)
    59* [label](service_ls.md#label)
    60* [mode](service_ls.md#mode)
    61* [name](service_ls.md#name)
    62
    63#### id
    64
    65The `id` filter matches all or the prefix of a service's ID.
    66
    67The following filter matches services with an ID starting with `0bcjw`:
    68
    69```console
    70$ docker service ls -f "id=0bcjw"
    71ID            NAME   MODE        REPLICAS  IMAGE
    720bcjwfh8ychr  redis  replicated  1/1       redis:3.0.6
    73```
    74
    75#### label
    76
    77The `label` filter matches services based on the presence of a `label` alone or
    78a `label` and a value.
    79
    80The following filter matches all services with a `project` label regardless of
    81its value:
    82
    83```console
    84$ docker service ls --filter label=project
    85ID            NAME       MODE        REPLICAS  IMAGE
    8601sl1rp6nj5u  frontend2  replicated  1/1       nginx:alpine
    8736xvvwwauej0  frontend   replicated  5/5       nginx:alpine
    8874nzcxxjv6fq  backend    replicated  3/3       redis:3.0.6
    89```
    90
    91The following filter matches only services with the `project` label with the
    92`project-a` value.
    93
    94```console
    95$ docker service ls --filter label=project=project-a
    96ID            NAME      MODE        REPLICAS  IMAGE
    9736xvvwwauej0  frontend  replicated  5/5       nginx:alpine
    9874nzcxxjv6fq  backend   replicated  3/3       redis:3.0.6
    99```
   100
   101#### mode
   102
   103The `mode` filter matches on the mode (either `replicated` or `global`) of a service.
   104
   105The following filter matches only `global` services.
   106
   107```console
   108$ docker service ls --filter mode=global
   109ID                  NAME                MODE                REPLICAS            IMAGE
   110w7y0v2yrn620        top                 global              1/1                 busybox
   111```
   112
   113#### name
   114
   115The `name` filter matches on all or the prefix of a service's name.
   116
   117The following filter matches services with a name starting with `redis`.
   118
   119```console
   120$ docker service ls --filter name=redis
   121ID            NAME   MODE        REPLICAS  IMAGE
   1220bcjwfh8ychr  redis  replicated  1/1       redis:3.0.6
   123```
   124
   125### <a name="format"></a> Format the output (--format)
   126
   127The formatting options (`--format`) pretty-prints services output
   128using a Go template.
   129
   130Valid placeholders for the Go template are listed below:
   131
   132| Placeholder | Description                             |
   133|-------------|-----------------------------------------|
   134| `.ID`       | Service ID                              |
   135| `.Name`     | Service name                            |
   136| `.Mode`     | Service mode (replicated, global)       |
   137| `.Replicas` | Service replicas                        |
   138| `.Image`    | Service image                           |
   139| `.Ports`    | Service ports published in ingress mode |
   140
   141When using the `--format` option, the `service ls` command will either
   142output the data exactly as the template declares or, when using the
   143`table` directive, includes column headers as well.
   144
   145The following example uses a template without headers and outputs the
   146`ID`, `Mode`, and `Replicas` entries separated by a colon (`:`) for all services:
   147
   148```console
   149$ docker service ls --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
   150
   1510zmvwuiu3vue: replicated 10/10
   152fm6uf97exkul: global 5/5
   153```
   154
   155To list all services in JSON format, use the `json` directive:
   156
   157```console
   158$ docker service ls --format json
   159{"ID":"ssniordqolsi","Image":"hello-world:latest","Mode":"replicated","Name":"hello","Ports":"","Replicas":"0/1"}
   160```
   161
   162## Related commands
   163
   164* [service create](service_create.md)
   165* [service inspect](service_inspect.md)
   166* [service logs](service_logs.md)
   167* [service ps](service_ps.md)
   168* [service rm](service_rm.md)
   169* [service rollback](service_rollback.md)
   170* [service scale](service_scale.md)
   171* [service update](service_update.md)

View as plain text