...

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

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

     1# service ps
     2
     3<!---MARKER_GEN_START-->
     4List the tasks of one or more services
     5
     6### Options
     7
     8| Name                                   | Type     | Default | Description                                |
     9|:---------------------------------------|:---------|:--------|:-------------------------------------------|
    10| [`-f`](#filter), [`--filter`](#filter) | `filter` |         | Filter output based on conditions provided |
    11| [`--format`](#format)                  | `string` |         | Pretty-print tasks using a Go template     |
    12| `--no-resolve`                         |          |         | Do not map IDs to Names                    |
    13| `--no-trunc`                           |          |         | Do not truncate output                     |
    14| `-q`, `--quiet`                        |          |         | Only display task IDs                      |
    15
    16
    17<!---MARKER_GEN_END-->
    18
    19## Description
    20
    21Lists the tasks that are running as part of the specified services.
    22
    23> **Note**
    24>
    25> This is a cluster management command, and must be executed on a swarm
    26> manager node. To learn about managers and workers, refer to the
    27> [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
    28> documentation.
    29
    30## Examples
    31
    32### List the tasks that are part of a service
    33
    34The following command shows all the tasks that are part of the `redis` service:
    35
    36```console
    37$ docker service ps redis
    38
    39ID             NAME      IMAGE        NODE      DESIRED STATE  CURRENT STATE          ERROR  PORTS
    400qihejybwf1x   redis.1   redis:3.0.5  manager1  Running        Running 8 seconds
    41bk658fpbex0d   redis.2   redis:3.0.5  worker2   Running        Running 9 seconds
    425ls5s5fldaqg   redis.3   redis:3.0.5  worker1   Running        Running 9 seconds
    438ryt076polmc   redis.4   redis:3.0.5  worker1   Running        Running 9 seconds
    441x0v8yomsncd   redis.5   redis:3.0.5  manager1  Running        Running 8 seconds
    4571v7je3el7rr   redis.6   redis:3.0.5  worker2   Running        Running 9 seconds
    464l3zm9b7tfr7   redis.7   redis:3.0.5  worker2   Running        Running 9 seconds
    479tfpyixiy2i7   redis.8   redis:3.0.5  worker1   Running        Running 9 seconds
    483w1wu13yupln   redis.9   redis:3.0.5  manager1  Running        Running 8 seconds
    498eaxrb2fqpbn   redis.10  redis:3.0.5  manager1  Running        Running 8 seconds
    50```
    51
    52In addition to running tasks, the output also shows the task history. For
    53example, after updating the service to use the `redis:3.0.6` image, the output
    54may look like this:
    55
    56```console
    57$ docker service ps redis
    58
    59ID            NAME         IMAGE        NODE      DESIRED STATE  CURRENT STATE                   ERROR  PORTS
    6050qe8lfnxaxk  redis.1      redis:3.0.6  manager1  Running        Running 6 seconds ago
    61ky2re9oz86r9   \_ redis.1  redis:3.0.5  manager1  Shutdown       Shutdown 8 seconds ago
    623s46te2nzl4i  redis.2      redis:3.0.6  worker2   Running        Running less than a second ago
    63nvjljf7rmor4   \_ redis.2  redis:3.0.6  worker2   Shutdown       Rejected 23 seconds ago        "No such image: redis@sha256:6…"
    64vtiuz2fpc0yb   \_ redis.2  redis:3.0.5  worker2   Shutdown       Shutdown 1 second ago
    65jnarweeha8x4  redis.3      redis:3.0.6  worker1   Running        Running 3 seconds ago
    66vs448yca2nz4   \_ redis.3  redis:3.0.5  worker1   Shutdown       Shutdown 4 seconds ago
    67jf1i992619ir  redis.4      redis:3.0.6  worker1   Running        Running 10 seconds ago
    68blkttv7zs8ee   \_ redis.4  redis:3.0.5  worker1   Shutdown       Shutdown 11 seconds ago
    69```
    70
    71The number of items in the task history is determined by the
    72`--task-history-limit` option that was set when initializing the swarm. You can
    73change the task history retention limit using the
    74[`docker swarm update`](swarm_update.md) command.
    75
    76When deploying a service, docker resolves the digest for the service's image,
    77and pins the service to that digest. The digest is not shown by default, but is
    78printed if `--no-trunc` is used. The `--no-trunc` option also shows the
    79non-truncated task ID, and error messages, as can be seen in the following
    80example:
    81
    82```console
    83$ docker service ps --no-trunc redis
    84
    85ID                          NAME         IMAGE                                                                                NODE      DESIRED STATE  CURRENT STATE            ERROR                                                                                           PORTS
    8650qe8lfnxaxksi9w2a704wkp7   redis.1      redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842  manager1  Running        Running 5 minutes ago
    87ky2re9oz86r9556i2szb8a8af   \_ redis.1   redis:3.0.5@sha256:f8829e00d95672c48c60f468329d6693c4bdd28d1f057e755f8ba8b40008682e  worker2   Shutdown       Shutdown 5 minutes ago
    88bk658fpbex0d57cqcwoe3jthu   redis.2      redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842  worker2   Running        Running 5 seconds
    89nvjljf7rmor4htv7l8rwcx7i7   \_ redis.2   redis:3.0.6@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842  worker2   Shutdown       Rejected 5 minutes ago   "No such image: redis@sha256:6a692a76c2081888b589e26e6ec835743119fe453d67ecf03df7de5b73d69842"
    90```
    91
    92### <a name="filter"></a> Filtering (--filter)
    93
    94The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there
    95is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`).
    96Multiple filter flags are combined as an `OR` filter. For example,
    97`-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks.
    98
    99The currently supported filters are:
   100
   101* [id](#id)
   102* [name](#name)
   103* [node](#node)
   104* [desired-state](#desired-state)
   105
   106
   107#### id
   108
   109The `id` filter matches on all or a prefix of a task's ID.
   110
   111```console
   112$ docker service ps -f "id=8" redis
   113
   114ID             NAME      IMAGE        NODE      DESIRED STATE  CURRENT STATE      ERROR  PORTS
   1158ryt076polmc   redis.4   redis:3.0.6  worker1   Running        Running 9 seconds
   1168eaxrb2fqpbn   redis.10  redis:3.0.6  manager1  Running        Running 8 seconds
   117```
   118
   119#### name
   120
   121The `name` filter matches on task names.
   122
   123```console
   124$ docker service ps -f "name=redis.1" redis
   125
   126ID            NAME     IMAGE        NODE      DESIRED STATE  CURRENT STATE      ERROR  PORTS
   127qihejybwf1x5  redis.1  redis:3.0.6  manager1  Running        Running 8 seconds
   128```
   129
   130
   131#### node
   132
   133The `node` filter matches on a node name or a node ID.
   134
   135```console
   136$ docker service ps -f "node=manager1" redis
   137
   138ID            NAME      IMAGE        NODE      DESIRED STATE  CURRENT STATE      ERROR  PORTS
   1390qihejybwf1x  redis.1   redis:3.0.6  manager1  Running        Running 8 seconds
   1401x0v8yomsncd  redis.5   redis:3.0.6  manager1  Running        Running 8 seconds
   1413w1wu13yupln  redis.9   redis:3.0.6  manager1  Running        Running 8 seconds
   1428eaxrb2fqpbn  redis.10  redis:3.0.6  manager1  Running        Running 8 seconds
   143```
   144
   145#### desired-state
   146
   147The `desired-state` filter can take the values `running`, `shutdown`, or `accepted`.
   148
   149### <a name="format"></a> Format the output (--format)
   150
   151The formatting options (`--format`) pretty-prints tasks output
   152using a Go template.
   153
   154Valid placeholders for the Go template are listed below:
   155
   156| Placeholder     | Description                                                      |
   157|-----------------|------------------------------------------------------------------|
   158| `.ID`           | Task ID                                                          |
   159| `.Name`         | Task name                                                        |
   160| `.Image`        | Task image                                                       |
   161| `.Node`         | Node ID                                                          |
   162| `.DesiredState` | Desired state of the task (`running`, `shutdown`, or `accepted`) |
   163| `.CurrentState` | Current state of the task                                        |
   164| `.Error`        | Error                                                            |
   165| `.Ports`        | Task published ports                                             |
   166
   167When using the `--format` option, the `service ps` command will either
   168output the data exactly as the template declares or, when using the
   169`table` directive, includes column headers as well.
   170
   171The following example uses a template without headers and outputs the
   172`Name` and `Image` entries separated by a colon (`:`) for all tasks:
   173
   174```console
   175$ docker service ps --format "{{.Name}}: {{.Image}}" top
   176
   177top.1: busybox
   178top.2: busybox
   179top.3: busybox
   180```
   181
   182## Related commands
   183
   184* [service create](service_create.md)
   185* [service inspect](service_inspect.md)
   186* [service logs](service_logs.md)
   187* [service ls](service_ls.md)
   188* [service rm](service_rm.md)
   189* [service rollback](service_rollback.md)
   190* [service scale](service_scale.md)
   191* [service update](service_update.md)

View as plain text