github.com/rsampaio/docker@v0.7.2-0.20150827203920-fdc73cc3fc31/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  weight=1
     9  +++
    10  <![end-metadata]-->
    11  
    12  # ps
    13  
    14      Usage: docker ps [OPTIONS]
    15  
    16      List containers
    17  
    18        -a, --all=false       Show all containers (default shows just running)
    19        --before=""           Show only container created before Id or Name
    20        -f, --filter=[]       Filter output based on conditions provided
    21        -l, --latest=false    Show the latest created container, include non-running
    22        -n=-1                 Show n last created containers, include non-running
    23        --no-trunc=false      Don't truncate output
    24        -q, --quiet=false     Only display numeric IDs
    25        -s, --size=false      Display total file sizes
    26        --since=""            Show created since Id or Name, include non-running
    27        --format=[]       Pretty-print containers using a Go template
    28  
    29  Running `docker ps --no-trunc` showing 2 linked containers.
    30  
    31      $ docker ps
    32      CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
    33      4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds       3300-3310/tcp       webapp
    34      d7886598dbe2        crosbymichael/redis:latest   /redis-server --dir    33 minutes ago       Up 33 minutes       6379/tcp            redis,webapp/db
    35  
    36  `docker ps` will show only running containers by default. To see all containers:
    37  `docker ps -a`
    38  
    39  `docker ps` will group exposed ports into a single range if possible. E.g., a container that exposes TCP ports `100, 101, 102` will display `100-102/tcp` in the `PORTS` column.
    40  
    41  ## Filtering
    42  
    43  The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more
    44  than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`)
    45  
    46  The currently supported filters are:
    47  
    48  * id (container's id)
    49  * label (`label=<key>` or `label=<key>=<value>`)
    50  * name (container's name)
    51  * exited (int - the code of exited containers. Only useful with `--all`)
    52  * status (created|restarting|running|paused|exited)
    53  
    54  
    55  #### Label
    56  
    57  The `label` filter matches containers based on the presence of a `label` alone or a `label` and a
    58  value.
    59  
    60  The following filter matches containers with the `color` label regardless of its value.
    61  
    62      $ docker ps --filter "label=color"
    63      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    64      673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
    65      d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
    66  
    67  The following filter matches containers with the `color` label with the `blue` value.
    68  
    69      $ docker ps --filter "label=color=blue"
    70      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
    71      d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
    72  
    73  #### Name
    74  
    75  The `name` filter matches on all or part of a container's name.
    76  
    77  The following filter matches all containers with a name containing the `nostalgic_stallman` string.
    78  
    79      $ docker ps --filter "name=nostalgic_stallman"
    80      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    81      9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
    82  
    83  You can also filter for a substring in a name as this shows:
    84  
    85      $ docker ps --filter "name=nostalgic"
    86      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    87      715ebfcee040        busybox             "top"               3 seconds ago       Up 1 seconds                            i_am_nostalgic
    88      9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
    89      673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
    90  
    91  #### Exited
    92  
    93  The `exited` filter matches containers by exist status code. For example, to filter for containers
    94  that have exited successfully:
    95  
    96      $ docker ps -a --filter 'exited=0'
    97      CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
    98      ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
    99      106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
   100      48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
   101  
   102  #### Status
   103  
   104  The `status` filter matches containers by status. You can filter using `created`, `restarting`, `running`, `paused` and `exited`. For example, to filter for `running` containers:
   105  
   106      $ docker ps --filter status=running
   107      CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
   108      715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
   109      d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
   110      9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
   111  
   112  To filter for `paused` containers:
   113  
   114      $ docker ps --filter status=paused
   115      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
   116      673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
   117  
   118  #### Ancestor
   119  
   120  The `ancestor` filter matches containers based on its image or a descendant of it. The filter supports the
   121  following image representation:
   122  
   123  - image
   124  - image:tag
   125  - image:tag@digest
   126  - short-id
   127  - full-id
   128  
   129  If you don't specify a `tag`, the `latest` tag is used. For example, to filter for containers that use the
   130  latest `ubuntu` image:
   131  
   132      $ docker ps --filter ancestor=ubuntu
   133      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   134      919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   135      5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
   136      82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   137      bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
   138  
   139  Match containers based on the `ubuntu-c1` image which, in this case, is a child of `ubuntu`:
   140  
   141      $ docker ps --filter ancestor=ubuntu-c1
   142      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   143      919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   144  
   145  Match containers based on the `ubuntu` version `12.04.5` image:
   146  
   147      $ docker ps --filter ancestor=ubuntu:12.04.5
   148      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   149      82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   150  
   151  The following matches containers based on the layer `d0e008c6cf02` or an image that have this layer
   152  in it's layer stack.
   153  
   154      $ docker ps --filter ancestor=d0e008c6cf02
   155      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   156      82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   157  
   158  
   159  ## Formatting
   160  
   161  The formatting option (`--format`) will pretty-print container output using a Go template.
   162  
   163  Valid placeholders for the Go template are listed below:
   164  
   165  Placeholder | Description
   166  ---- | ----
   167  `.ID` | Container ID
   168  `.Image` | Image ID
   169  `.Command` | Quoted command
   170  `.CreatedAt` | Time when the container was created.
   171  `.RunningFor` | Elapsed time since the container was started.
   172  `.Ports` | Exposed ports.
   173  `.Status` | Container status.
   174  `.Size` | Container disk size.
   175  `.Labels` | All labels assigned to the container.
   176  `.Label` | Value of a specific label for this container. For example `{{.Label "com.docker.swarm.cpu"}}`
   177  
   178  When using the `--format` option, the `ps` command will either output the data exactly as the template
   179  declares or, when using the `table` directive, will include column headers as well.
   180  
   181  The following example uses a template without headers and outputs the `ID` and `Command`
   182  entries separated by a colon for all running containers:
   183  
   184      $ docker ps --format "{{.ID}}: {{.Command}}"
   185      a87ecb4f327c: /bin/sh -c #(nop) MA
   186      01946d9d34d8: /bin/sh -c #(nop) MA
   187      c1d3b0166030: /bin/sh -c yum -y up
   188      41d50ecd2f57: /bin/sh -c #(nop) MA
   189  
   190  To list all running containers with their labels in a table format you can use:
   191  
   192      $ docker ps --format "table {{.ID}}\t{{.Labels}}"
   193      CONTAINER ID        LABELS
   194      a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
   195      01946d9d34d8
   196      c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
   197      41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd