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