github.com/panekj/cli@v0.0.0-20230304125325-467dd2f3797e/docs/reference/commandline/service_ls.md (about) 1 # service ls 2 3 <!---MARKER_GEN_START--> 4 List 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 23 This command lists services 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 34 On a manager node: 35 36 ```console 37 $ docker service ls 38 39 ID NAME MODE REPLICAS IMAGE 40 c8wgl7q4ndfd frontend replicated 5/5 nginx:alpine 41 dmu1ept4cxcf redis replicated 3/3 redis:3.0.6 42 iwe3278osahj mongo global 7/7 mongo:3.3 43 hh08h9uu8uwr job replicated-job 1/1 (3/5 completed) nginx:latest 44 ``` 45 46 The `REPLICAS` column shows both the *actual* and *desired* number of tasks for 47 the service. If the service is in `replicated-job` or `global-job`, it will 48 additionally show the completion status of the job as completed tasks over 49 total tasks the job will execute. 50 51 ### <a name="filter"></a> Filtering (--filter) 52 53 The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more 54 than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) 55 56 The 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 65 The `id` filter matches all or part of a service's id. 66 67 ```console 68 $ docker service ls -f "id=0bcjw" 69 ID NAME MODE REPLICAS IMAGE 70 0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 71 ``` 72 73 #### label 74 75 The `label` filter matches services based on the presence of a `label` alone or 76 a `label` and a value. 77 78 The following filter matches all services with a `project` label regardless of 79 its value: 80 81 ```console 82 $ docker service ls --filter label=project 83 ID NAME MODE REPLICAS IMAGE 84 01sl1rp6nj5u frontend2 replicated 1/1 nginx:alpine 85 36xvvwwauej0 frontend replicated 5/5 nginx:alpine 86 74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 87 ``` 88 89 The following filter matches only services with the `project` label with the 90 `project-a` value. 91 92 ```console 93 $ docker service ls --filter label=project=project-a 94 ID NAME MODE REPLICAS IMAGE 95 36xvvwwauej0 frontend replicated 5/5 nginx:alpine 96 74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 97 ``` 98 99 #### mode 100 101 The `mode` filter matches on the mode (either `replicated` or `global`) of a service. 102 103 The following filter matches only `global` services. 104 105 ```console 106 $ docker service ls --filter mode=global 107 ID NAME MODE REPLICAS IMAGE 108 w7y0v2yrn620 top global 1/1 busybox 109 ``` 110 111 #### name 112 113 The `name` filter matches on all or part of a service's name. 114 115 The following filter matches services with a name containing `redis`. 116 117 ```console 118 $ docker service ls --filter name=redis 119 ID NAME MODE REPLICAS IMAGE 120 0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 121 ``` 122 123 ### <a name="format"></a> Format the output (--format) 124 125 The formatting options (`--format`) pretty-prints services output 126 using a Go template. 127 128 Valid placeholders for the Go template are listed below: 129 130 | Placeholder | Description | 131 |-------------|-----------------------------------------| 132 | `.ID` | Service ID | 133 | `.Name` | Service name | 134 | `.Mode` | Service mode (replicated, global) | 135 | `.Replicas` | Service replicas | 136 | `.Image` | Service image | 137 | `.Ports` | Service ports published in ingress mode | 138 139 When using the `--format` option, the `service ls` command will either 140 output the data exactly as the template declares or, when using the 141 `table` directive, includes column headers as well. 142 143 The following example uses a template without headers and outputs the 144 `ID`, `Mode`, and `Replicas` entries separated by a colon (`:`) for all services: 145 146 ```console 147 $ docker service ls --format "{{.ID}}: {{.Mode}} {{.Replicas}}" 148 149 0zmvwuiu3vue: replicated 10/10 150 fm6uf97exkul: global 5/5 151 ``` 152 153 To list all services in JSON format, use the `json` directive: 154 155 ```console 156 $ docker service ls --format json 157 {"ID":"ssniordqolsi","Image":"hello-world:latest","Mode":"replicated","Name":"hello","Ports":"","Replicas":"0/1"} 158 ``` 159 160 ## Related commands 161 162 * [service create](service_create.md) 163 * [service inspect](service_inspect.md) 164 * [service logs](service_logs.md) 165 * [service ps](service_ps.md) 166 * [service rm](service_rm.md) 167 * [service rollback](service_rollback.md) 168 * [service scale](service_scale.md) 169 * [service update](service_update.md)