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

     1  ---
     2  title: "ps"
     3  description: "The ps command description and usage"
     4  keywords: "container, running, list"
     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  # ps
    17  
    18  ```markdown
    19  Usage: docker ps [OPTIONS]
    20  
    21  List containers
    22  
    23  Options:
    24    -a, --all             Show all containers (default shows just running)
    25    -f, --filter value    Filter output based on conditions provided (default [])
    26                          - ancestor=(<image-name>[:tag]|<image-id>|<image@digest>)
    27                            containers created from an image or a descendant.
    28                          - before=(<container-name>|<container-id>)
    29                          - expose=(<port>[/<proto>]|<startport-endport>/[<proto>])
    30                          - exited=<int> an exit code of <int>
    31                          - health=(starting|healthy|unhealthy|none)
    32                          - id=<ID> a container's ID
    33                          - isolation=(`default`|`process`|`hyperv`) (Windows daemon only)
    34                          - is-task=(true|false)
    35                          - label=<key> or label=<key>=<value>
    36                          - name=<string> a container's name
    37                          - network=(<network-id>|<network-name>)
    38                          - publish=(<port>[/<proto>]|<startport-endport>/[<proto>])
    39                          - since=(<container-name>|<container-id>)
    40                          - status=(created|restarting|removing|running|paused|exited)
    41                          - volume=(<volume name>|<mount point destination>)
    42        --format string   Pretty-print containers using a Go template
    43        --help            Print usage
    44    -n, --last int        Show n last created containers (includes all states) (default -1)
    45    -l, --latest          Show the latest created container (includes all states)
    46        --no-trunc        Don't truncate output
    47    -q, --quiet           Only display numeric IDs
    48    -s, --size            Display total file sizes
    49  ```
    50  
    51  ## Examples
    52  
    53  ### Prevent truncating output
    54  
    55  Running `docker ps --no-trunc` showing 2 linked containers.
    56  
    57  ```bash
    58  $ docker ps
    59  
    60  CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
    61  4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds       3300-3310/tcp       webapp
    62  d7886598dbe2        crosbymichael/redis:latest   /redis-server --dir    33 minutes ago       Up 33 minutes       6379/tcp            redis,webapp/db
    63  ```
    64  
    65  ### Show both running and stopped containers
    66  
    67  The `docker ps` command only shows running containers by default. To see all
    68  containers, use the `-a` (or `--all`) flag:
    69  
    70  ```bash
    71  $ docker ps -a
    72  ```
    73  
    74  `docker ps` groups exposed ports into a single range if possible. E.g., a
    75  container that exposes TCP ports `100, 101, 102` displays `100-102/tcp` in
    76  the `PORTS` column.
    77  
    78  ### Filtering
    79  
    80  The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more
    81  than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`)
    82  
    83  The currently supported filters are:
    84  
    85  | Filter                | Description                                                                                                                          |
    86  |:----------------------|:-------------------------------------------------------------------------------------------------------------------------------------|
    87  | `id`                  | Container's ID                                                                                                                       |
    88  | `name`                | Container's name                                                                                                                     |
    89  | `label`               | An arbitrary string representing either a key or a key-value pair. Expressed as `<key>` or `<key>=<value>`                           |
    90  | `exited`              | An integer representing the container's exit code. Only useful with `--all`.                                                         |
    91  | `status`              | One of `created`, `restarting`, `running`, `removing`, `paused`, `exited`, or `dead`                                                 |
    92  | `ancestor`            | Filters containers which share a given image as an ancestor. Expressed as `<image-name>[:<tag>]`,  `<image id>`, or `<image@digest>` |
    93  | `before` or `since`   | Filters containers created before or after a given container ID or name                                                              |
    94  | `volume`              | Filters running containers which have mounted a given volume or bind mount.                                                          |
    95  | `network`             | Filters running containers connected to a given network.                                                                             |
    96  | `publish` or `expose` | Filters containers which publish or expose a given port. Expressed as `<port>[/<proto>]` or `<startport-endport>/[<proto>]`          |
    97  | `health`              | Filters containers based on their healthcheck status. One of `starting`, `healthy`, `unhealthy` or `none`.                           |
    98  | `isolation`           | Windows daemon only. One of `default`, `process`, or `hyperv`.                                                                       |
    99  | `is-task`             | Filters containers that are a "task" for a service. Boolean option (`true` or `false`)                                               |
   100  
   101  
   102  #### label
   103  
   104  The `label` filter matches containers based on the presence of a `label` alone or a `label` and a
   105  value.
   106  
   107  The following filter matches containers with the `color` label regardless of its value.
   108  
   109  ```bash
   110  $ docker ps --filter "label=color"
   111  
   112  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   113  673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
   114  d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
   115  ```
   116  
   117  The following filter matches containers with the `color` label with the `blue` value.
   118  
   119  ```bash
   120  $ docker ps --filter "label=color=blue"
   121  
   122  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   123  d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
   124  ```
   125  
   126  #### name
   127  
   128  The `name` filter matches on all or part of a container's name.
   129  
   130  The following filter matches all containers with a name containing the `nostalgic_stallman` string.
   131  
   132  ```bash
   133  $ docker ps --filter "name=nostalgic_stallman"
   134  
   135  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   136  9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
   137  ```
   138  
   139  You can also filter for a substring in a name as this shows:
   140  
   141  ```bash
   142  $ docker ps --filter "name=nostalgic"
   143  
   144  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   145  715ebfcee040        busybox             "top"               3 seconds ago       Up 1 second                             i_am_nostalgic
   146  9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
   147  673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
   148  ```
   149  
   150  #### exited
   151  
   152  The `exited` filter matches containers by exist status code. For example, to
   153  filter for containers that have exited successfully:
   154  
   155  ```bash
   156  $ docker ps -a --filter 'exited=0'
   157  
   158  CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
   159  ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
   160  106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
   161  48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
   162  ```
   163  
   164  #### Filter by exit signal
   165  
   166  You can use a filter to locate containers that exited with status of `137`
   167  meaning a `SIGKILL(9)` killed them.
   168  
   169  ```none
   170  $ docker ps -a --filter 'exited=137'
   171  
   172  CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
   173  b3e1c0ed5bfe        ubuntu:latest       "sleep 1000"           12 seconds ago      Exited (137) 5 seconds ago                       grave_kowalevski
   174  a2eb5558d669        redis:latest        "/entrypoint.sh redi   2 hours ago         Exited (137) 2 hours ago                         sharp_lalande
   175  ```
   176  
   177  Any of these events result in a `137` status:
   178  
   179  * the `init` process of the container is killed manually
   180  * `docker kill` kills the container
   181  * Docker daemon restarts which kills all running containers
   182  
   183  #### status
   184  
   185  The `status` filter matches containers by status. You can filter using
   186  `created`, `restarting`, `running`, `removing`, `paused`, `exited` and `dead`. For example,
   187  to filter for `running` containers:
   188  
   189  ```bash
   190  $ docker ps --filter status=running
   191  
   192  CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
   193  715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
   194  d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
   195  9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
   196  ```
   197  
   198  To filter for `paused` containers:
   199  
   200  ```bash
   201  $ docker ps --filter status=paused
   202  
   203  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
   204  673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
   205  ```
   206  
   207  #### ancestor
   208  
   209  The `ancestor` filter matches containers based on its image or a descendant of
   210  it. The filter supports the following image representation:
   211  
   212  - `image`
   213  - `image:tag`
   214  - `image:tag@digest`
   215  - `short-id`
   216  - `full-id`
   217  
   218  If you don't specify a `tag`, the `latest` tag is used. For example, to filter
   219  for containers that use the latest `ubuntu` image:
   220  
   221  ```bash
   222  $ docker ps --filter ancestor=ubuntu
   223  
   224  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   225  919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   226  5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
   227  82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   228  bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
   229  ```
   230  
   231  Match containers based on the `ubuntu-c1` image which, in this case, is a child
   232  of `ubuntu`:
   233  
   234  ```bash
   235  $ docker ps --filter ancestor=ubuntu-c1
   236  
   237  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   238  919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   239  ```
   240  
   241  Match containers based on the `ubuntu` version `12.04.5` image:
   242  
   243  ```bash
   244  $ docker ps --filter ancestor=ubuntu:12.04.5
   245  
   246  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   247  82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   248  ```
   249  
   250  The following matches containers based on the layer `d0e008c6cf02` or an image
   251  that have this layer in its layer stack.
   252  
   253  ```bash
   254  $ docker ps --filter ancestor=d0e008c6cf02
   255  
   256  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   257  82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   258  ```
   259  
   260  #### Create time
   261  
   262  ##### before
   263  
   264  The `before` filter shows only containers created before the container with
   265  given id or name. For example, having these containers created:
   266  
   267  ```bash
   268  $ docker ps
   269  
   270  CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   271  9c3527ed70ce        busybox     "top"         14 seconds ago       Up 15 seconds                          desperate_dubinsky
   272  4aace5031105        busybox     "top"         48 seconds ago       Up 49 seconds                          focused_hamilton
   273  6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   274  ```
   275  
   276  Filtering with `before` would give:
   277  
   278  ```bash
   279  $ docker ps -f before=9c3527ed70ce
   280  
   281  CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   282  4aace5031105        busybox     "top"         About a minute ago   Up About a minute                      focused_hamilton
   283  6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   284  ```
   285  
   286  ##### since
   287  
   288  The `since` filter shows only containers created since the container with given
   289  id or name. For example, with the same containers as in `before` filter:
   290  
   291  ```bash
   292  $ docker ps -f since=6e63f6ff38b0
   293  
   294  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   295  9c3527ed70ce        busybox     "top"         10 minutes ago      Up 10 minutes                           desperate_dubinsky
   296  4aace5031105        busybox     "top"         10 minutes ago      Up 10 minutes                           focused_hamilton
   297  ```
   298  
   299  #### volume
   300  
   301  The `volume` filter shows only containers that mount a specific volume or have
   302  a volume mounted in a specific path:
   303  
   304  ```bash
   305  $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
   306  CONTAINER ID        MOUNTS
   307  9c3527ed70ce        remote-volume
   308  
   309  $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
   310  CONTAINER ID        MOUNTS
   311  9c3527ed70ce        remote-volume
   312  ```
   313  
   314  #### network
   315  
   316  The `network` filter shows only containers that are connected to a network with
   317  a given name or id.
   318  
   319  The following filter matches all containers that are connected to a network
   320  with a name containing `net1`.
   321  
   322  ```bash
   323  $ docker run -d --net=net1 --name=test1 ubuntu top
   324  $ docker run -d --net=net2 --name=test2 ubuntu top
   325  
   326  $ docker ps --filter network=net1
   327  
   328  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   329  9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
   330  ```
   331  
   332  The network filter matches on both the network's name and id. The following
   333  example shows all containers that are attached to the `net1` network, using
   334  the network id as a filter;
   335  
   336  ```bash
   337  $ docker network inspect --format "{{.ID}}" net1
   338  
   339  8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
   340  
   341  $ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
   342  
   343  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   344  9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
   345  ```
   346  
   347  #### publish and expose
   348  
   349  The `publish` and `expose` filters show only containers that have published or exposed port with a given port
   350  number, port range, and/or protocol. The default protocol is `tcp` when not specified.
   351  
   352  The following filter matches all containers that have published port of 80:
   353  
   354  ```bash
   355  $ docker run -d --publish=80 busybox top
   356  $ docker run -d --expose=8080 busybox top
   357  
   358  $ docker ps -a
   359  
   360  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
   361  9833437217a5        busybox             "top"               5 seconds ago       Up 4 seconds        8080/tcp                dreamy_mccarthy
   362  fc7e477723b7        busybox             "top"               50 seconds ago      Up 50 seconds       0.0.0.0:32768->80/tcp   admiring_roentgen
   363  
   364  $ docker ps --filter publish=80
   365  
   366  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                   NAMES
   367  fc7e477723b7        busybox             "top"               About a minute ago   Up About a minute   0.0.0.0:32768->80/tcp   admiring_roentgen
   368  ```
   369  
   370  The following filter matches all containers that have exposed TCP port in the range of `8000-8080`:
   371  ```bash
   372  $ docker ps --filter expose=8000-8080/tcp
   373  
   374  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   375  9833437217a5        busybox             "top"               21 seconds ago      Up 19 seconds       8080/tcp            dreamy_mccarthy
   376  ```
   377  
   378  The following filter matches all containers that have exposed UDP port `80`:
   379  ```bash
   380  $ docker ps --filter publish=80/udp
   381  
   382  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   383  ```
   384  
   385  ### Formatting
   386  
   387  The formatting option (`--format`) pretty-prints container output using a Go
   388  template.
   389  
   390  Valid placeholders for the Go template are listed below:
   391  
   392  | Placeholder   | Description                                                                                     |
   393  |:--------------|:------------------------------------------------------------------------------------------------|
   394  | `.ID`         | Container ID                                                                                    |
   395  | `.Image`      | Image ID                                                                                        |
   396  | `.Command`    | Quoted command                                                                                  |
   397  | `.CreatedAt`  | Time when the container was created.                                                            |
   398  | `.RunningFor` | Elapsed time since the container was started.                                                   |
   399  | `.Ports`      | Exposed ports.                                                                                  |
   400  | `.Status`     | Container status.                                                                               |
   401  | `.Size`       | Container disk size.                                                                            |
   402  | `.Names`      | Container names.                                                                                |
   403  | `.Labels`     | All labels assigned to the container.                                                           |
   404  | `.Label`      | Value of a specific label for this container. For example `'{{.Label "com.docker.swarm.cpu"}}'` |
   405  | `.Mounts`     | Names of the volumes mounted in this container.                                                 |
   406  | `.Networks`   | Names of the networks attached to this container.                                               |
   407  
   408  When using the `--format` option, the `ps` command will either output the data
   409  exactly as the template declares or, when using the `table` directive, includes
   410  column headers as well.
   411  
   412  The following example uses a template without headers and outputs the `ID` and
   413  `Command` entries separated by a colon for all running containers:
   414  
   415  ```bash
   416  $ docker ps --format "{{.ID}}: {{.Command}}"
   417  
   418  a87ecb4f327c: /bin/sh -c #(nop) MA
   419  01946d9d34d8: /bin/sh -c #(nop) MA
   420  c1d3b0166030: /bin/sh -c yum -y up
   421  41d50ecd2f57: /bin/sh -c #(nop) MA
   422  ```
   423  
   424  To list all running containers with their labels in a table format you can use:
   425  
   426  ```bash
   427  $ docker ps --format "table {{.ID}}\t{{.Labels}}"
   428  
   429  CONTAINER ID        LABELS
   430  a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
   431  01946d9d34d8
   432  c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
   433  41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
   434  ```