github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/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|dead)
    59  * ancestor (`<image-name>[:<tag>]`,  `<image id>` or `<image@digest>`) - filters containers that were created from the given image or a descendant.
    60  * before (container's id or name) - filters containers created before given id or name
    61  * since (container's id or name) - filters containers created since given id or name
    62  * isolation (default|process|hyperv)   (Windows daemon only)
    63  * volume (volume name or mount point) - filters containers that mount volumes.
    64  
    65  
    66  #### Label
    67  
    68  The `label` filter matches containers based on the presence of a `label` alone or a `label` and a
    69  value.
    70  
    71  The following filter matches containers with the `color` label regardless of its value.
    72  
    73      $ docker ps --filter "label=color"
    74      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    75      673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
    76      d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
    77  
    78  The following filter matches containers with the `color` label with the `blue` value.
    79  
    80      $ docker ps --filter "label=color=blue"
    81      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
    82      d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
    83  
    84  #### Name
    85  
    86  The `name` filter matches on all or part of a container's name.
    87  
    88  The following filter matches all containers with a name containing the `nostalgic_stallman` string.
    89  
    90      $ docker ps --filter "name=nostalgic_stallman"
    91      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    92      9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
    93  
    94  You can also filter for a substring in a name as this shows:
    95  
    96      $ docker ps --filter "name=nostalgic"
    97      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    98      715ebfcee040        busybox             "top"               3 seconds ago       Up 1 seconds                            i_am_nostalgic
    99      9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
   100      673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
   101  
   102  #### Exited
   103  
   104  The `exited` filter matches containers by exist status code. For example, to filter for containers
   105  that have exited successfully:
   106  
   107      $ docker ps -a --filter 'exited=0'
   108      CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
   109      ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
   110      106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
   111      48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
   112  
   113  #### Status
   114  
   115  The `status` filter matches containers by status. You can filter using `created`, `restarting`, `running`, `paused`, `exited` and `dead`. For example, to filter for `running` containers:
   116  
   117      $ docker ps --filter status=running
   118      CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
   119      715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
   120      d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
   121      9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
   122  
   123  To filter for `paused` containers:
   124  
   125      $ docker ps --filter status=paused
   126      CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
   127      673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
   128  
   129  #### Ancestor
   130  
   131  The `ancestor` filter matches containers based on its image or a descendant of it. The filter supports the
   132  following image representation:
   133  
   134  - image
   135  - image:tag
   136  - image:tag@digest
   137  - short-id
   138  - full-id
   139  
   140  If you don't specify a `tag`, the `latest` tag is used. For example, to filter for containers that use the
   141  latest `ubuntu` image:
   142  
   143      $ docker ps --filter ancestor=ubuntu
   144      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   145      919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   146      5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
   147      82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   148      bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
   149  
   150  Match containers based on the `ubuntu-c1` image which, in this case, is a child of `ubuntu`:
   151  
   152      $ docker ps --filter ancestor=ubuntu-c1
   153      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   154      919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   155  
   156  Match containers based on the `ubuntu` version `12.04.5` image:
   157  
   158      $ docker ps --filter ancestor=ubuntu:12.04.5
   159      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   160      82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   161  
   162  The following matches containers based on the layer `d0e008c6cf02` or an image that have this layer
   163  in it's layer stack.
   164  
   165      $ docker ps --filter ancestor=d0e008c6cf02
   166      CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   167      82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   168  
   169  #### Before
   170  
   171  The `before` filter shows only containers created before the container with given id or name. For example, 
   172  having these containers created:
   173  
   174      $ docker ps
   175      CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   176      9c3527ed70ce        busybox     "top"         14 seconds ago       Up 15 seconds                          desperate_dubinsky
   177      4aace5031105        busybox     "top"         48 seconds ago       Up 49 seconds                          focused_hamilton
   178      6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   179  
   180  Filtering with `before` would give:
   181  
   182      $ docker ps -f before=9c3527ed70ce
   183      CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   184      4aace5031105        busybox     "top"         About a minute ago   Up About a minute                      focused_hamilton
   185      6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   186  
   187  #### Since
   188  
   189  The `since` filter shows only containers created since the container with given id or name. For example,
   190  with the same containers as in `before` filter:
   191  
   192      $ docker ps -f since=6e63f6ff38b0
   193      CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   194      9c3527ed70ce        busybox     "top"         10 minutes ago      Up 10 minutes                           desperate_dubinsky
   195      4aace5031105        busybox     "top"         10 minutes ago      Up 10 minutes                           focused_hamilton
   196  
   197  #### Volume
   198  
   199  The `volume` filter shows only containers that mount a specific volume or have a volume mounted in a specific path:
   200  
   201      $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
   202      CONTAINER ID        MOUNTS
   203      9c3527ed70ce        remote-volume
   204  
   205      $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
   206      CONTAINER ID        MOUNTS
   207      9c3527ed70ce        remote-volume
   208  
   209  
   210  ## Formatting
   211  
   212  The formatting option (`--format`) will pretty-print container output using a Go template.
   213  
   214  Valid placeholders for the Go template are listed below:
   215  
   216  Placeholder | Description
   217  ---- | ----
   218  `.ID` | Container ID
   219  `.Image` | Image ID
   220  `.Command` | Quoted command
   221  `.CreatedAt` | Time when the container was created.
   222  `.RunningFor` | Elapsed time since the container was started.
   223  `.Ports` | Exposed ports.
   224  `.Status` | Container status.
   225  `.Size` | Container disk size.
   226  `.Names` | Container names.
   227  `.Labels` | All labels assigned to the container.
   228  `.Label` | Value of a specific label for this container. For example `{{.Label "com.docker.swarm.cpu"}}`
   229  `.Mounts` | Names of the volumes mounted in this container.
   230  
   231  When using the `--format` option, the `ps` command will either output the data exactly as the template
   232  declares or, when using the `table` directive, will include column headers as well.
   233  
   234  The following example uses a template without headers and outputs the `ID` and `Command`
   235  entries separated by a colon for all running containers:
   236  
   237      $ docker ps --format "{{.ID}}: {{.Command}}"
   238      a87ecb4f327c: /bin/sh -c #(nop) MA
   239      01946d9d34d8: /bin/sh -c #(nop) MA
   240      c1d3b0166030: /bin/sh -c yum -y up
   241      41d50ecd2f57: /bin/sh -c #(nop) MA
   242  
   243  To list all running containers with their labels in a table format you can use:
   244  
   245      $ docker ps --format "table {{.ID}}\t{{.Labels}}"
   246      CONTAINER ID        LABELS
   247      a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
   248      01946d9d34d8
   249      c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
   250      41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd