github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/reference/commandline/ps.md (about)

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