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