github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/docs/reference/commandline/stack_ps.md (about)

     1  ---
     2  title: "stack ps"
     3  description: "The stack ps command description and usage"
     4  keywords: "stack, ps"
     5  ---
     6  
     7  # stack ps
     8  
     9  ```markdown
    10  Usage:  docker stack ps [OPTIONS] STACK
    11  
    12  List the tasks in the stack
    13  
    14  Options:
    15    -f, --filter filter         Filter output based on conditions provided
    16        --format string         Pretty-print tasks using a Go template
    17        --help                  Print usage
    18        --kubeconfig string     Kubernetes config file
    19        --namespace string      Kubernetes namespace to use
    20        --no-resolve            Do not map IDs to Names
    21        --no-trunc              Do not truncate output
    22        --orchestrator string   Orchestrator to use (swarm|kubernetes|all)
    23    -q, --quiet                 Only display task IDs
    24  ```
    25  
    26  ## Description
    27  
    28  Lists the tasks that are running as part of the specified stack.
    29  
    30  > **Note**
    31  >
    32  > This is a cluster management command, and must be executed on a swarm
    33  > manager node. To learn about managers and workers, refer to the
    34  > [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
    35  > documentation.
    36  
    37  ## Examples
    38  
    39  ### List the tasks that are part of a stack
    40  
    41  The following command shows all the tasks that are part of the `voting` stack:
    42  
    43  ```console
    44  $ docker stack ps voting
    45  
    46  ID                  NAME                  IMAGE                                          NODE   DESIRED STATE  CURRENT STATE          ERROR  PORTS
    47  xim5bcqtgk1b        voting_worker.1       dockersamples/examplevotingapp_worker:latest   node2  Running        Running 2 minutes ago
    48  q7yik0ks1in6        voting_result.1       dockersamples/examplevotingapp_result:before   node1  Running        Running 2 minutes ago
    49  rx5yo0866nfx        voting_vote.1         dockersamples/examplevotingapp_vote:before     node3  Running        Running 2 minutes ago
    50  tz6j82jnwrx7        voting_db.1           postgres:9.4                                   node1  Running        Running 2 minutes ago
    51  w48spazhbmxc        voting_redis.1        redis:alpine                                   node2  Running        Running 3 minutes ago
    52  6jj1m02freg1        voting_visualizer.1   dockersamples/visualizer:stable                node1  Running        Running 2 minutes ago
    53  kqgdmededccb        voting_vote.2         dockersamples/examplevotingapp_vote:before     node2  Running        Running 2 minutes ago
    54  t72q3z038jeh        voting_redis.2        redis:alpine                                   node3  Running        Running 3 minutes ago
    55  ```
    56  
    57  ### <a name="filter"></a> Filtering (--filter)
    58  
    59  The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there
    60  is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`).
    61  Multiple filter flags are combined as an `OR` filter. For example,
    62  `-f name=redis.1 -f name=redis.7` returns both `redis.1` and `redis.7` tasks.
    63  
    64  The currently supported filters are:
    65  
    66  * [id](#id)
    67  * [name](#name)
    68  * [node](#node)
    69  * [desired-state](#desired-state)
    70  
    71  #### id
    72  
    73  The `id` filter matches on all or a prefix of a task's ID.
    74  
    75  ```console
    76  $ docker stack ps -f "id=t" voting
    77  
    78  ID                  NAME                IMAGE               NODE         DESIRED STATE       CURRENTSTATE            ERROR  PORTS
    79  tz6j82jnwrx7        voting_db.1         postgres:9.4        node1        Running             Running 14 minutes ago
    80  t72q3z038jeh        voting_redis.2      redis:alpine        node3        Running             Running 14 minutes ago
    81  ```
    82  
    83  #### name
    84  
    85  The `name` filter matches on task names.
    86  
    87  ```console
    88  $ docker stack ps -f "name=voting_redis" voting
    89  
    90  ID                  NAME                IMAGE               NODE         DESIRED STATE       CURRENTSTATE            ERROR  PORTS
    91  w48spazhbmxc        voting_redis.1      redis:alpine        node2        Running             Running 17 minutes ago
    92  t72q3z038jeh        voting_redis.2      redis:alpine        node3        Running             Running 17 minutes ago
    93  ```
    94  
    95  #### node
    96  
    97  The `node` filter matches on a node name or a node ID.
    98  
    99  ```console
   100  $ docker stack ps -f "node=node1" voting
   101  
   102  ID                  NAME                  IMAGE                                          NODE   DESIRED STATE  CURRENT STATE          ERROR  PORTS
   103  q7yik0ks1in6        voting_result.1       dockersamples/examplevotingapp_result:before   node1  Running        Running 18 minutes ago
   104  tz6j82jnwrx7        voting_db.1           postgres:9.4                                   node1  Running        Running 18 minutes ago
   105  6jj1m02freg1        voting_visualizer.1   dockersamples/visualizer:stable                node1  Running        Running 18 minutes ago
   106  ```
   107  
   108  #### desired-state
   109  
   110  The `desired-state` filter can take the values `running`, `shutdown`, `ready` or `accepted`.
   111  
   112  ```console
   113  $ docker stack ps -f "desired-state=running" voting
   114  
   115  ID                  NAME                  IMAGE                                          NODE   DESIRED STATE  CURRENT STATE           ERROR  PORTS
   116  xim5bcqtgk1b        voting_worker.1       dockersamples/examplevotingapp_worker:latest   node2  Running        Running 21 minutes ago
   117  q7yik0ks1in6        voting_result.1       dockersamples/examplevotingapp_result:before   node1  Running        Running 21 minutes ago
   118  rx5yo0866nfx        voting_vote.1         dockersamples/examplevotingapp_vote:before     node3  Running        Running 21 minutes ago
   119  tz6j82jnwrx7        voting_db.1           postgres:9.4                                   node1  Running        Running 21 minutes ago
   120  w48spazhbmxc        voting_redis.1        redis:alpine                                   node2  Running        Running 21 minutes ago
   121  6jj1m02freg1        voting_visualizer.1   dockersamples/visualizer:stable                node1  Running        Running 21 minutes ago
   122  kqgdmededccb        voting_vote.2         dockersamples/examplevotingapp_vote:before     node2  Running        Running 21 minutes ago
   123  t72q3z038jeh        voting_redis.2        redis:alpine                                   node3  Running        Running 21 minutes ago
   124  ```
   125  
   126  ### <a name="format"></a> Format the output (--format)
   127  
   128  The formatting options (`--format`) pretty-prints tasks output using a Go template.
   129  
   130  Valid placeholders for the Go template are listed below:
   131  
   132  | Placeholder     | Description                                                      |
   133  |-----------------|------------------------------------------------------------------|
   134  | `.ID`           | Task ID                                                          |
   135  | `.Name`         | Task name                                                        |
   136  | `.Image`        | Task image                                                       |
   137  | `.Node`         | Node ID                                                          |
   138  | `.DesiredState` | Desired state of the task (`running`, `shutdown`, or `accepted`) |
   139  | `.CurrentState` | Current state of the task                                        |
   140  | `.Error`        | Error                                                            |
   141  | `.Ports`        | Task published ports                                             |
   142  
   143  When using the `--format` option, the `stack ps` command will either
   144  output the data exactly as the template declares or, when using the
   145  `table` directive, includes column headers as well.
   146  
   147  The following example uses a template without headers and outputs the
   148  `Name` and `Image` entries separated by a colon (`:`) for all tasks:
   149  
   150  ```console
   151  $ docker stack ps --format "{{.Name}}: {{.Image}}" voting
   152  
   153  voting_worker.1: dockersamples/examplevotingapp_worker:latest
   154  voting_result.1: dockersamples/examplevotingapp_result:before
   155  voting_vote.1: dockersamples/examplevotingapp_vote:before
   156  voting_db.1: postgres:9.4
   157  voting_redis.1: redis:alpine
   158  voting_visualizer.1: dockersamples/visualizer:stable
   159  voting_vote.2: dockersamples/examplevotingapp_vote:before
   160  voting_redis.2: redis:alpine
   161  ```
   162  
   163  ### <a name="no-resolve"></a> Do not map IDs to Names (--no-resolve)
   164  
   165  The `--no-resolve` option shows IDs for task name, without mapping IDs to Names.
   166  
   167  ```console
   168  $ docker stack ps --no-resolve voting
   169  
   170  ID                  NAME                          IMAGE                                          NODE                        DESIRED STATE  CURRENT STATE            ERROR  PORTS
   171  xim5bcqtgk1b        10z9fjfqzsxnezo4hb81p8mqg.1   dockersamples/examplevotingapp_worker:latest   qaqt4nrzo775jrx6detglho01   Running        Running 30 minutes ago
   172  q7yik0ks1in6        hbxltua1na7mgqjnidldv5m65.1   dockersamples/examplevotingapp_result:before   mxpaef1tlh23s052erw88a4w5   Running        Running 30 minutes ago
   173  rx5yo0866nfx        qyprtqw1g5nrki557i974ou1d.1   dockersamples/examplevotingapp_vote:before     kanqcxfajd1r16wlnqcblobmm   Running        Running 31 minutes ago
   174  tz6j82jnwrx7        122f0xxngg17z52be7xspa72x.1   postgres:9.4                                   mxpaef1tlh23s052erw88a4w5   Running        Running 31 minutes ago
   175  w48spazhbmxc        tg61x8myx563ueo3urmn1ic6m.1   redis:alpine                                   qaqt4nrzo775jrx6detglho01   Running        Running 31 minutes ago
   176  6jj1m02freg1        8cqlyi444kzd3panjb7edh26v.1   dockersamples/visualizer:stable                mxpaef1tlh23s052erw88a4w5   Running        Running 31 minutes ago
   177  kqgdmededccb        qyprtqw1g5nrki557i974ou1d.2   dockersamples/examplevotingapp_vote:before     qaqt4nrzo775jrx6detglho01   Running        Running 31 minutes ago
   178  t72q3z038jeh        tg61x8myx563ueo3urmn1ic6m.2   redis:alpine                                   kanqcxfajd1r16wlnqcblobmm   Running        Running 31 minutes ago
   179  ```
   180  
   181  ### <a name="no-trunc"></a> Do not truncate output (--no-trunc)
   182  
   183  When deploying a service, docker resolves the digest for the service's
   184  image, and pins the service to that digest. The digest is not shown by
   185  default, but is printed if `--no-trunc` is used. The `--no-trunc` option
   186  also shows the non-truncated task IDs, and error-messages, as can be seen below:
   187  
   188  ```console
   189  $ docker stack ps --no-trunc voting
   190  
   191  ID                          NAME                  IMAGE                                                                                                                 NODE   DESIRED STATE  CURREN STATE           ERROR  PORTS
   192  xim5bcqtgk1bxqz91jzo4a1s5   voting_worker.1       dockersamples/examplevotingapp_worker:latest@sha256:3e4ddf59c15f432280a2c0679c4fc5a2ee5a797023c8ef0d3baf7b1385e9fed   node2  Running        Runnin 32 minutes ago
   193  q7yik0ks1in6kv32gg6y6yjf7   voting_result.1       dockersamples/examplevotingapp_result:before@sha256:83b56996e930c292a6ae5187fda84dd6568a19d97cdb933720be15c757b7463   node1  Running        Runnin 32 minutes ago
   194  rx5yo0866nfxc58zf4irsss6n   voting_vote.1         dockersamples/examplevotingapp_vote:before@sha256:8e64b182c87de902f2b72321c89b4af4e2b942d76d0b772532ff27ec4c6ebf6     node3  Running        Runnin 32 minutes ago
   195  tz6j82jnwrx7n2offljp3mn03   voting_db.1           postgres:9.4@sha256:6046af499eae34d2074c0b53f9a8b404716d415e4a03e68bc1d2f8064f2b027                                   node1  Running        Runnin 32 minutes ago
   196  w48spazhbmxcmbjfi54gs7x90   voting_redis.1        redis:alpine@sha256:9cd405cd1ec1410eaab064a1383d0d8854d1ef74a54e1e4a92fb4ec7bdc3ee7                                   node2  Running        Runnin 32 minutes ago
   197  6jj1m02freg1n3z9n1evrzsbl   voting_visualizer.1   dockersamples/visualizer:stable@sha256:f924ad66c8e94b10baaf7bdb9cd491ef4e982a1d048a56a17e02bf5945401e5                node1  Running        Runnin 32 minutes ago
   198  kqgdmededccbhz2wuc0e9hx7g   voting_vote.2         dockersamples/examplevotingapp_vote:before@sha256:8e64b182c87de902f2b72321c89b4af4e2b942d76d0b772532ff27ec4c6ebf6     node2  Running        Runnin 32 minutes ago
   199  t72q3z038jehe1wbh9gdum076   voting_redis.2        redis:alpine@sha256:9cd405cd1ec1410eaab064a1383d0d8854d1ef74a54e1e4a92fb4ec7bdc3ee7                                   node3  Running        Runnin 32 minutes ago
   200  ```
   201  
   202  ### <a name="quiet"></a> Only display task IDs (-q, --quiet)
   203  
   204  The `-q ` or `--quiet` option only shows IDs of the tasks in the stack.
   205  This example outputs all task IDs of the "voting" stack;
   206  
   207  ```console
   208  $ docker stack ps -q voting
   209  xim5bcqtgk1b
   210  q7yik0ks1in6
   211  rx5yo0866nfx
   212  tz6j82jnwrx7
   213  w48spazhbmxc
   214  6jj1m02freg1
   215  kqgdmededccb
   216  t72q3z038jeh
   217  ```
   218  
   219  This option can be used to perform batch operations. For example, you can use
   220  the task IDs as input for other commands, such as `docker inspect`. The
   221  following example inspects all tasks of the "voting" stack;
   222  
   223  ```console
   224  $ docker inspect $(docker stack ps -q voting)
   225  
   226  [
   227      {
   228          "ID": "xim5bcqtgk1b1gk0krq1",
   229          "Version": {
   230  <...>
   231  ```
   232  
   233  ## Related commands
   234  
   235  * [stack deploy](stack_deploy.md)
   236  * [stack ls](stack_ls.md)
   237  * [stack rm](stack_rm.md)
   238  * [stack services](stack_services.md)