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