github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/service_ps.md (about) 1 --- 2 title: "service ps" 3 description: "The service ps command description and usage" 4 keywords: "service, tasks, ps" 5 aliases: ["/engine/reference/commandline/service_tasks/"] 6 --- 7 8 <!-- This file is maintained within the docker/cli GitHub 9 repository at https://github.com/docker/cli/. Make all 10 pull requests against that repo. If you see this file in 11 another repository, consider it read-only there, as it will 12 periodically be overwritten by the definitive file. Pull 13 requests which include edits to this file in other repositories 14 will be rejected. 15 --> 16 17 # service ps 18 19 ```Markdown 20 Usage: docker service ps [OPTIONS] SERVICE [SERVICE...] 21 22 List the tasks of one or more services 23 24 Options: 25 -f, --filter filter Filter output based on conditions provided 26 --format string Pretty-print tasks using a Go template 27 --help Print usage 28 --no-resolve Do not map IDs to Names 29 --no-trunc Do not truncate output 30 -q, --quiet Only display task IDs 31 ``` 32 33 ## Description 34 35 Lists the tasks that are running as part of the specified services. This command 36 has to be run targeting a manager node. 37 38 ## Examples 39 40 ### List the tasks that are part of a service 41 42 The following command shows all the tasks that are part of the `redis` service: 43 44 ```bash 45 $ docker service ps redis 46 47 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 48 0qihejybwf1x redis.1 redis:3.0.5 manager1 Running Running 8 seconds 49 bk658fpbex0d redis.2 redis:3.0.5 worker2 Running Running 9 seconds 50 5ls5s5fldaqg redis.3 redis:3.0.5 worker1 Running Running 9 seconds 51 8ryt076polmc redis.4 redis:3.0.5 worker1 Running Running 9 seconds 52 1x0v8yomsncd redis.5 redis:3.0.5 manager1 Running Running 8 seconds 53 71v7je3el7rr redis.6 redis:3.0.5 worker2 Running Running 9 seconds 54 4l3zm9b7tfr7 redis.7 redis:3.0.5 worker2 Running Running 9 seconds 55 9tfpyixiy2i7 redis.8 redis:3.0.5 worker1 Running Running 9 seconds 56 3w1wu13yupln redis.9 redis:3.0.5 manager1 Running Running 8 seconds 57 8eaxrb2fqpbn redis.10 redis:3.0.5 manager1 Running Running 8 seconds 58 ``` 59 60 In addition to _running_ tasks, the output also shows the task history. For 61 example, after updating the service to use the `redis:3.0.6` image, the output 62 may look like this: 63 64 ```bash 65 $ docker service ps redis 66 67 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 68 50qe8lfnxaxk redis.1 redis:3.0.6 manager1 Running Running 6 seconds ago 69 ky2re9oz86r9 \_ redis.1 redis:3.0.5 manager1 Shutdown Shutdown 8 seconds ago 70 3s46te2nzl4i redis.2 redis:3.0.6 worker2 Running Running less than a second ago 71 nvjljf7rmor4 \_ redis.2 redis:3.0.6 worker2 Shutdown Rejected 23 seconds ago "No such image: redis@sha256:6…" 72 vtiuz2fpc0yb \_ redis.2 redis:3.0.5 worker2 Shutdown Shutdown 1 second ago 73 jnarweeha8x4 redis.3 redis:3.0.6 worker1 Running Running 3 seconds ago 74 vs448yca2nz4 \_ redis.3 redis:3.0.5 worker1 Shutdown Shutdown 4 seconds ago 75 jf1i992619ir redis.4 redis:3.0.6 worker1 Running Running 10 seconds ago 76 blkttv7zs8ee \_ redis.4 redis:3.0.5 worker1 Shutdown Shutdown 11 seconds ago 77 ``` 78 79 The number of items in the task history is determined by the 80 `--task-history-limit` option that was set when initializing the swarm. You can 81 change the task history retention limit using the 82 [`docker swarm update`](swarm_update.md) command. 83 84 When deploying a service, docker resolves the digest for the service's 85 image, and pins the service to that digest. The digest is not shown by 86 default, but is printed if `--no-trunc` is used. The `--no-trunc` option 87 also shows the non-truncated task ID, and error-messages, as can be seen below; 88 89 ```bash 90 $ docker service ps --no-trunc redis 91 92 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 93 50qe8lfnxaxksi9w2a704wkp7 redis.1 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 manager1 Running Running 5 minutes ago 94 ky2re9oz86r9556i2szb8a8af \_ redis.1 redis:3.0.5@sha256:f8829e00d95672c48c60f468329d6693c4bdd28d1f057e755f8ba8b40008682e worker2 Shutdown Shutdown 5 minutes ago 95 bk658fpbex0d57cqcwoe3jthu redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Running Running 5 seconds 96 nvjljf7rmor4htv7l8rwcx7i7 \_ redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Shutdown Rejected 5 minutes ago "No such image: redis@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842" 97 ``` 98 99 ### Filtering 100 101 The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there 102 is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). 103 Multiple filter flags are combined as an `OR` filter. For example, 104 `-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks. 105 106 The currently supported filters are: 107 108 * [id](#id) 109 * [name](#name) 110 * [node](#node) 111 * [desired-state](#desired-state) 112 113 114 #### id 115 116 The `id` filter matches on all or a prefix of a task's ID. 117 118 ```bash 119 $ docker service ps -f "id=8" redis 120 121 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 122 8ryt076polmc redis.4 redis:3.0.6 worker1 Running Running 9 seconds 123 8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds 124 ``` 125 126 #### name 127 128 The `name` filter matches on task names. 129 130 ```bash 131 $ docker service ps -f "name=redis.1" redis 132 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 133 qihejybwf1x5 redis.1 redis:3.0.6 manager1 Running Running 8 seconds 134 ``` 135 136 137 #### node 138 139 The `node` filter matches on a node name or a node ID. 140 141 ```bash 142 $ docker service ps -f "node=manager1" redis 143 ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS 144 0qihejybwf1x redis.1 redis:3.0.6 manager1 Running Running 8 seconds 145 1x0v8yomsncd redis.5 redis:3.0.6 manager1 Running Running 8 seconds 146 3w1wu13yupln redis.9 redis:3.0.6 manager1 Running Running 8 seconds 147 8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds 148 ``` 149 150 #### desired-state 151 152 The `desired-state` filter can take the values `running`, `shutdown`, or `accepted`. 153 154 ### Formatting 155 156 The formatting options (`--format`) pretty-prints tasks output 157 using a Go template. 158 159 Valid placeholders for the Go template are listed below: 160 161 Placeholder | Description 162 ----------------|------------------------------------------------------------------------------------------ 163 `.ID` | Task ID 164 `.Name` | Task name 165 `.Image` | Task image 166 `.Node` | Node ID 167 `.DesiredState` | Desired state of the task (`running`, `shutdown`, or `accepted`) 168 `.CurrentState` | Current state of the task 169 `.Error` | Error 170 `.Ports` | Task published ports 171 172 When using the `--format` option, the `service ps` command will either 173 output the data exactly as the template declares or, when using the 174 `table` directive, includes column headers as well. 175 176 The following example uses a template without headers and outputs the 177 `Name` and `Image` entries separated by a colon for all tasks: 178 179 ```bash 180 $ docker service ps --format "{{.Name}}: {{.Image}}" top 181 top.1: busybox 182 top.2: busybox 183 top.3: busybox 184 ``` 185 186 ## Related commands 187 188 * [service create](service_create.md) 189 * [service inspect](service_inspect.md) 190 * [service logs](service_logs.md) 191 * [service ls](service_ls.md) 192 * [service rm](service_rm.md) 193 * [service rollback](service_rollback.md) 194 * [service scale](service_scale.md) 195 * [service update](service_update.md)