github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/stack_services.md (about)

     1  # stack services
     2  
     3  <!---MARKER_GEN_START-->
     4  List the services in the stack
     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` |         | Format output using a custom template:<br>'table':            Print output in table format with column headers (default)<br>'table TEMPLATE':   Print output in table format using the given Go template<br>'json':             Print in JSON format<br>'TEMPLATE':         Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
    12  | `-q`, `--quiet`                        |          |         | Only display IDs                                                                                                                                                                                                                                                                                                                                                                                                                     |
    13  
    14  
    15  <!---MARKER_GEN_END-->
    16  
    17  ## Description
    18  
    19  Lists the services that are running as part of the specified stack.
    20  
    21  > **Note**
    22  >
    23  > This is a cluster management command, and must be executed on a swarm
    24  > manager node. To learn about managers and workers, refer to the
    25  > [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
    26  > documentation.
    27  
    28  ## Examples
    29  
    30  The following command shows all services in the `myapp` stack:
    31  
    32  ```console
    33  $ docker stack services myapp
    34  
    35  ID            NAME            REPLICAS  IMAGE                                                                          COMMAND
    36  7be5ei6sqeye  myapp_web       1/1       nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f
    37  dn7m7nhhfb9y  myapp_db        1/1       mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
    38  ```
    39  
    40  ### <a name="filter"></a> Filtering (--filter)
    41  
    42  The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there
    43  is more than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`).
    44  Multiple filter flags are combined as an `OR` filter.
    45  
    46  The following command shows both the `web` and `db` services:
    47  
    48  ```console
    49  $ docker stack services --filter name=myapp_web --filter name=myapp_db myapp
    50  
    51  ID            NAME            REPLICAS  IMAGE                                                                          COMMAND
    52  7be5ei6sqeye  myapp_web       1/1       nginx@sha256:23f809e7fd5952e7d5be065b4d3643fbbceccd349d537b62a123ef2201bc886f
    53  dn7m7nhhfb9y  myapp_db        1/1       mysql@sha256:a9a5b559f8821fe73d58c3606c812d1c044868d42c63817fa5125fd9d8b7b539
    54  ```
    55  
    56  The currently supported filters are:
    57  
    58  * id / ID (`--filter id=7be5ei6sqeye`, or `--filter ID=7be5ei6sqeye`)
    59  * label (`--filter label=key=value`)
    60  * mode (`--filter mode=replicated`, or `--filter mode=global`)
    61    * Swarm: not supported
    62  * name (`--filter name=myapp_web`)
    63  * node (`--filter node=mynode`)
    64    * Swarm: not supported
    65  * service (`--filter service=web`)
    66    * Swarm: not supported
    67  
    68  ### <a name="format"></a> Format the output (--format)
    69  
    70  The formatting options (`--format`) pretty-prints services output
    71  using a Go template.
    72  
    73  Valid placeholders for the Go template are listed below:
    74  
    75  | Placeholder | Description                       |
    76  |-------------|-----------------------------------|
    77  | `.ID`       | Service ID                        |
    78  | `.Name`     | Service name                      |
    79  | `.Mode`     | Service mode (replicated, global) |
    80  | `.Replicas` | Service replicas                  |
    81  | `.Image`    | Service image                     |
    82  
    83  When using the `--format` option, the `stack services` command will either
    84  output the data exactly as the template declares or, when using the
    85  `table` directive, includes column headers as well.
    86  
    87  The following example uses a template without headers and outputs the
    88  `ID`, `Mode`, and `Replicas` entries separated by a colon (`:`) for all services:
    89  
    90  ```console
    91  $ docker stack services --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
    92  
    93  0zmvwuiu3vue: replicated 10/10
    94  fm6uf97exkul: global 5/5
    95  ```
    96  
    97  To list all services in JSON format, use the `json` directive:
    98  
    99  ```console
   100  $ docker stack services ls --format json
   101  {"ID":"0axqbl293vwm","Image":"localstack/localstack:latest","Mode":"replicated","Name":"myapp_localstack","Ports":"*:4566-\u003e4566/tcp, *:8080-\u003e8080/tcp","Replicas":"0/1"}
   102  {"ID":"384xvtzigz3p","Image":"redis:6.0.9-alpine3.12","Mode":"replicated","Name":"myapp_redis","Ports":"*:6379-\u003e6379/tcp","Replicas":"1/1"}
   103  {"ID":"hyujct8cnjkk","Image":"postgres:13.2-alpine","Mode":"replicated","Name":"myapp_repos-db","Ports":"*:5432-\u003e5432/tcp","Replicas":"0/1"}
   104  ```
   105  
   106  
   107  ## Related commands
   108  
   109  * [stack deploy](stack_deploy.md)
   110  * [stack ls](stack_ls.md)
   111  * [stack ps](stack_ps.md)
   112  * [stack rm](stack_rm.md)