2016-10-14 18:30:36 -04:00
---
title: "service ps"
description: "The service ps command description and usage"
2016-11-03 18:48:30 -04:00
keywords: "service, tasks, ps"
2016-10-14 18:30:36 -04:00
aliases: ["/engine/reference/commandline/service_tasks/"]
---
2016-06-17 19:51:17 -04:00
2016-07-19 17:01:31 -04:00
# service ps
2016-06-17 19:51:17 -04:00
```Markdown
2017-03-29 17:06:58 -04:00
Usage: docker service ps [OPTIONS] SERVICE [SERVICE...]
2016-06-17 19:51:17 -04:00
2016-07-29 11:20:03 -04:00
List the tasks of one or more services
2016-06-17 19:51:17 -04:00
Options:
2016-10-27 20:02:57 -04:00
-f, --filter filter Filter output based on conditions provided
2016-11-07 00:54:40 -05:00
--format string Pretty-print tasks using a Go template
2016-10-27 20:02:57 -04:00
--help Print usage
--no-resolve Do not map IDs to Names
--no-trunc Do not truncate output
-q, --quiet Only display task IDs
2016-06-17 19:51:17 -04:00
```
2017-02-07 18:42:48 -05:00
## Description
2018-12-23 06:27:52 -05:00
Lists the tasks that are running as part of the specified services.
2020-04-19 11:08:37 -04:00
> **Note**
>
> 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
## Examples
2017-02-07 18:42:48 -05:00
### List the tasks that are part of a service
2016-06-17 19:51:17 -04:00
The following command shows all the tasks that are part of the `redis` service:
2021-08-21 08:54:14 -04:00
```console
2016-07-19 17:01:31 -04:00
$ docker service ps redis
2016-12-13 07:30:58 -05:00
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
0qihejybwf1x redis.1 redis:3.0.5 manager1 Running Running 8 seconds
bk658fpbex0d redis.2 redis:3.0.5 worker2 Running Running 9 seconds
5ls5s5fldaqg redis.3 redis:3.0.5 worker1 Running Running 9 seconds
8ryt076polmc redis.4 redis:3.0.5 worker1 Running Running 9 seconds
1x0v8yomsncd redis.5 redis:3.0.5 manager1 Running Running 8 seconds
71v7je3el7rr redis.6 redis:3.0.5 worker2 Running Running 9 seconds
4l3zm9b7tfr7 redis.7 redis:3.0.5 worker2 Running Running 9 seconds
9tfpyixiy2i7 redis.8 redis:3.0.5 worker1 Running Running 9 seconds
3w1wu13yupln redis.9 redis:3.0.5 manager1 Running Running 8 seconds
8eaxrb2fqpbn redis.10 redis:3.0.5 manager1 Running Running 8 seconds
```
In addition to _running_ tasks, the output also shows the task history. For
example, after updating the service to use the `redis:3.0.6` image, the output
may look like this:
2021-08-21 08:54:14 -04:00
```console
2016-12-13 07:30:58 -05:00
$ docker service ps redis
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
50qe8lfnxaxk redis.1 redis:3.0.6 manager1 Running Running 6 seconds ago
ky2re9oz86r9 \_ redis.1 redis:3.0.5 manager1 Shutdown Shutdown 8 seconds ago
3s46te2nzl4i redis.2 redis:3.0.6 worker2 Running Running less than a second ago
nvjljf7rmor4 \_ redis.2 redis:3.0.6 worker2 Shutdown Rejected 23 seconds ago "No such image: redis@sha256:6…"
vtiuz2fpc0yb \_ redis.2 redis:3.0.5 worker2 Shutdown Shutdown 1 second ago
jnarweeha8x4 redis.3 redis:3.0.6 worker1 Running Running 3 seconds ago
vs448yca2nz4 \_ redis.3 redis:3.0.5 worker1 Shutdown Shutdown 4 seconds ago
jf1i992619ir redis.4 redis:3.0.6 worker1 Running Running 10 seconds ago
blkttv7zs8ee \_ redis.4 redis:3.0.5 worker1 Shutdown Shutdown 11 seconds ago
2016-06-17 19:51:17 -04:00
```
2016-12-13 07:30:58 -05:00
The number of items in the task history is determined by the
`--task-history-limit` option that was set when initializing the swarm. You can
change the task history retention limit using the
[`docker swarm update` ](swarm_update.md ) command.
2016-11-21 11:39:58 -05:00
When deploying a service, docker resolves the digest for the service's
image, and pins the service to that digest. The digest is not shown by
2016-12-13 07:30:58 -05:00
default, but is printed if `--no-trunc` is used. The `--no-trunc` option
also shows the non-truncated task ID, and error-messages, as can be seen below;
2016-11-21 11:39:58 -05:00
2021-08-21 08:54:14 -04:00
```console
2016-11-21 11:39:58 -05:00
$ docker service ps --no-trunc redis
2016-12-13 07:30:58 -05:00
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
50qe8lfnxaxksi9w2a704wkp7 redis.1 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 manager1 Running Running 5 minutes ago
ky2re9oz86r9556i2szb8a8af \_ redis.1 redis:3.0.5@sha256:f8829e00d95672c48c60f468329d6693c4bdd28d1f057e755f8ba8b40008682e worker2 Shutdown Shutdown 5 minutes ago
bk658fpbex0d57cqcwoe3jthu redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Running Running 5 seconds
nvjljf7rmor4htv7l8rwcx7i7 \_ redis.2 redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842 worker2 Shutdown Rejected 5 minutes ago "No such image: redis@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842"
2016-11-21 11:39:58 -05:00
```
2016-06-17 19:51:17 -04:00
2022-03-30 09:05:29 -04:00
### <a name=filter></a> Filtering (--filter)
2016-06-17 19:51:17 -04:00
The filtering flag (`-f` or `--filter` ) format is a `key=value` pair. If there
is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"` ).
2016-07-07 14:43:18 -04:00
Multiple filter flags are combined as an `OR` filter. For example,
`-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks.
2016-06-17 19:51:17 -04:00
The currently supported filters are:
* [id ](#id )
* [name ](#name )
2016-09-29 21:55:52 -04:00
* [node ](#node )
2016-06-29 12:20:32 -04:00
* [desired-state ](#desired-state )
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
The `id` filter matches on all or a prefix of a task's ID.
2021-08-21 08:54:14 -04:00
```console
2016-07-19 17:01:31 -04:00
$ docker service ps -f "id=8" redis
2016-12-13 07:30:58 -05:00
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
8ryt076polmc redis.4 redis:3.0.6 worker1 Running Running 9 seconds
8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds
2016-06-17 19:51:17 -04:00
```
2017-02-07 18:42:48 -05:00
#### name
2016-06-17 19:51:17 -04:00
The `name` filter matches on task names.
2021-08-21 08:54:14 -04:00
```console
2016-07-19 17:01:31 -04:00
$ docker service ps -f "name=redis.1" redis
2021-08-21 08:54:14 -04:00
2016-12-13 07:30:58 -05:00
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
qihejybwf1x5 redis.1 redis:3.0.6 manager1 Running Running 8 seconds
2016-06-17 19:51:17 -04:00
```
2017-02-07 18:42:48 -05:00
#### node
2016-09-29 21:55:52 -04:00
The `node` filter matches on a node name or a node ID.
2021-08-21 08:54:14 -04:00
```console
2016-09-29 21:55:52 -04:00
$ docker service ps -f "node=manager1" redis
2021-08-21 08:54:14 -04:00
2016-12-13 07:30:58 -05:00
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
0qihejybwf1x redis.1 redis:3.0.6 manager1 Running Running 8 seconds
1x0v8yomsncd redis.5 redis:3.0.6 manager1 Running Running 8 seconds
3w1wu13yupln redis.9 redis:3.0.6 manager1 Running Running 8 seconds
8eaxrb2fqpbn redis.10 redis:3.0.6 manager1 Running Running 8 seconds
2016-09-29 21:55:52 -04:00
```
2016-06-29 12:20:32 -04:00
#### desired-state
2016-06-29 10:16:31 -04:00
2017-03-29 16:13:28 -04:00
The `desired-state` filter can take the values `running` , `shutdown` , or `accepted` .
2016-06-29 10:16:31 -04:00
2022-03-30 09:05:29 -04:00
### <a name=format></a> Format the output (--format)
2016-11-07 00:54:40 -05:00
The formatting options (`--format`) pretty-prints tasks 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` | Task ID |
| `.Name` | Task name |
| `.Image` | Task image |
| `.Node` | Node ID |
| `.DesiredState` | Desired state of the task (`running`, `shutdown` , or `accepted` ) |
| `.CurrentState` | Current state of the task |
| `.Error` | Error |
| `.Ports` | Task published ports |
2016-11-07 00:54:40 -05:00
When using the `--format` option, the `service ps` 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
`Name` and `Image` entries separated by a colon (`:`) for all tasks:
2016-11-07 00:54:40 -05:00
2021-08-21 08:54:14 -04:00
```console
2016-11-07 00:54:40 -05:00
$ docker service ps --format "{{.Name}}: {{.Image}}" top
2021-08-21 08:54:14 -04:00
2016-11-07 00:54:40 -05:00
top.1: busybox
top.2: busybox
top.3: busybox
```
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 )
2016-06-17 19:51:17 -04:00
* [service ls ](service_ls.md )
* [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 )