github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/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 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 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 the prefix of a service's ID. 66 67 The following filter matches services with an ID starting with `0bcjw`: 68 69 ```console 70 $ docker service ls -f "id=0bcjw" 71 ID NAME MODE REPLICAS IMAGE 72 0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 73 ``` 74 75 #### label 76 77 The `label` filter matches services based on the presence of a `label` alone or 78 a `label` and a value. 79 80 The following filter matches all services with a `project` label regardless of 81 its value: 82 83 ```console 84 $ docker service ls --filter label=project 85 ID NAME MODE REPLICAS IMAGE 86 01sl1rp6nj5u frontend2 replicated 1/1 nginx:alpine 87 36xvvwwauej0 frontend replicated 5/5 nginx:alpine 88 74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 89 ``` 90 91 The 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 96 ID NAME MODE REPLICAS IMAGE 97 36xvvwwauej0 frontend replicated 5/5 nginx:alpine 98 74nzcxxjv6fq backend replicated 3/3 redis:3.0.6 99 ``` 100 101 #### mode 102 103 The `mode` filter matches on the mode (either `replicated` or `global`) of a service. 104 105 The following filter matches only `global` services. 106 107 ```console 108 $ docker service ls --filter mode=global 109 ID NAME MODE REPLICAS IMAGE 110 w7y0v2yrn620 top global 1/1 busybox 111 ``` 112 113 #### name 114 115 The `name` filter matches on all or the prefix of a service's name. 116 117 The following filter matches services with a name starting with `redis`. 118 119 ```console 120 $ docker service ls --filter name=redis 121 ID NAME MODE REPLICAS IMAGE 122 0bcjwfh8ychr redis replicated 1/1 redis:3.0.6 123 ``` 124 125 ### <a name="format"></a> Format the output (--format) 126 127 The formatting options (`--format`) pretty-prints services output 128 using a Go template. 129 130 Valid 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 141 When using the `--format` option, the `service ls` command will either 142 output the data exactly as the template declares or, when using the 143 `table` directive, includes column headers as well. 144 145 The 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 151 0zmvwuiu3vue: replicated 10/10 152 fm6uf97exkul: global 5/5 153 ``` 154 155 To 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)