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