github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/docs/reference/commandline/service_ls.md (about)

     1  ---
     2  title: "service ls"
     3  description: "The service ls command description and usage"
     4  keywords: "service, ls"
     5  ---
     6  
     7  <!-- This file is maintained within the docker/cli GitHub
     8       repository at https://github.com/docker/cli/. Make all
     9       pull requests against that repo. If you see this file in
    10       another repository, consider it read-only there, as it will
    11       periodically be overwritten by the definitive file. Pull
    12       requests which include edits to this file in other repositories
    13       will be rejected.
    14  -->
    15  
    16  # service ls
    17  
    18  ```Markdown
    19  Usage:	docker service ls [OPTIONS]
    20  
    21  List services
    22  
    23  Aliases:
    24    ls, list
    25  
    26  Options:
    27    -f, --filter filter   Filter output based on conditions provided
    28        --format string   Pretty-print services using a Go template
    29        --help            Print usage
    30    -q, --quiet           Only display IDs
    31  ```
    32  
    33  ## Description
    34  
    35  This command when run targeting a manager, lists services are running in the
    36  swarm.
    37  
    38  ## Examples
    39  
    40  On a manager node:
    41  
    42  ```bash
    43  $ docker service ls
    44  
    45  ID            NAME      MODE        REPLICAS    IMAGE
    46  c8wgl7q4ndfd  frontend  replicated  5/5         nginx:alpine
    47  dmu1ept4cxcf  redis     replicated  3/3         redis:3.0.6
    48  iwe3278osahj  mongo     global      7/7         mongo:3.3
    49  ```
    50  
    51  The `REPLICAS` column shows both the *actual* and *desired* number of tasks for
    52  the service.
    53  
    54  ### Filtering
    55  
    56  The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more
    57  than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`)
    58  
    59  The currently supported filters are:
    60  
    61  * [id](service_ls.md#id)
    62  * [label](service_ls.md#label)
    63  * [mode](service_ls.md#mode)
    64  * [name](service_ls.md#name)
    65  
    66  #### id
    67  
    68  The `id` filter matches all or part of a service's id.
    69  
    70  ```bash
    71  $ docker service ls -f "id=0bcjw"
    72  ID            NAME   MODE        REPLICAS  IMAGE
    73  0bcjwfh8ychr  redis  replicated  1/1       redis:3.0.6
    74  ```
    75  
    76  #### label
    77  
    78  The `label` filter matches services based on the presence of a `label` alone or
    79  a `label` and a value.
    80  
    81  The following filter matches all services with a `project` label regardless of
    82  its value:
    83  
    84  ```bash
    85  $ docker service ls --filter label=project
    86  ID            NAME       MODE        REPLICAS  IMAGE
    87  01sl1rp6nj5u  frontend2  replicated  1/1       nginx:alpine
    88  36xvvwwauej0  frontend   replicated  5/5       nginx:alpine
    89  74nzcxxjv6fq  backend    replicated  3/3       redis:3.0.6
    90  ```
    91  
    92  The following filter matches only services with the `project` label with the
    93  `project-a` value.
    94  
    95  ```bash
    96  $ docker service ls --filter label=project=project-a
    97  ID            NAME      MODE        REPLICAS  IMAGE
    98  36xvvwwauej0  frontend  replicated  5/5       nginx:alpine
    99  74nzcxxjv6fq  backend   replicated  3/3       redis:3.0.6
   100  ```
   101  
   102  #### mode
   103  
   104  The `mode` filter matches on the mode (either `replicated` or `global`) of a service.
   105  
   106  The following filter matches only `global` services.
   107  
   108  ```bash
   109  $ docker service ls --filter mode=global
   110  ID                  NAME                MODE                REPLICAS            IMAGE
   111  w7y0v2yrn620        top                 global              1/1                 busybox
   112  ```
   113  
   114  #### name
   115  
   116  The `name` filter matches on all or part of a service's name.
   117  
   118  The following filter matches services with a name containing `redis`.
   119  
   120  ```bash
   121  $ docker service ls --filter name=redis
   122  ID            NAME   MODE        REPLICAS  IMAGE
   123  0bcjwfh8ychr  redis  replicated  1/1       redis:3.0.6
   124  ```
   125  
   126  ### Formatting
   127  
   128  The formatting options (`--format`) pretty-prints services output
   129  using a Go template.
   130  
   131  Valid placeholders for the Go template are listed below:
   132  
   133  Placeholder | Description
   134  ------------|------------------------------------------------------------------------------------------
   135  `.ID`       | Service ID
   136  `.Name`     | Service name
   137  `.Mode`     | Service mode (replicated, global)
   138  `.Replicas` | Service replicas
   139  `.Image`    | Service image
   140  `.Ports`    | Service ports published in ingress mode
   141  
   142  When using the `--format` option, the `service ls` command will either
   143  output the data exactly as the template declares or, when using the
   144  `table` directive, includes column headers as well.
   145  
   146  The following example uses a template without headers and outputs the
   147  `ID`, `Mode`, and `Replicas` entries separated by a colon for all services:
   148  
   149  ```bash
   150  $ docker service ls --format "{{.ID}}: {{.Mode}} {{.Replicas}}"
   151  
   152  0zmvwuiu3vue: replicated 10/10
   153  fm6uf97exkul: global 5/5
   154  ```
   155  
   156  ## Related commands
   157  
   158  * [service create](service_create.md)
   159  * [service inspect](service_inspect.md)
   160  * [service logs](service_logs.md)
   161  * [service ps](service_ps.md)
   162  * [service rm](service_rm.md)
   163  * [service rollback](service_rollback.md)
   164  * [service scale](service_scale.md)
   165  * [service update](service_update.md)