github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/docs/reference/commandline/ps.md (about)

     1  ---
     2  title: "ps"
     3  description: "The ps command description and usage"
     4  keywords: "container, running, list"
     5  ---
     6  
     7  # ps
     8  
     9  ```markdown
    10  Usage: docker ps [OPTIONS]
    11  
    12  List containers
    13  
    14  Options:
    15    -a, --all             Show all containers (default shows just running)
    16    -f, --filter value    Filter output based on conditions provided (default [])
    17                          - ancestor=(<image-name>[:tag]|<image-id>|<image@digest>)
    18                            containers created from an image or a descendant.
    19                          - before=(<container-name>|<container-id>)
    20                          - expose=(<port>[/<proto>]|<startport-endport>/[<proto>])
    21                          - exited=<int> an exit code of <int>
    22                          - health=(starting|healthy|unhealthy|none)
    23                          - id=<ID> a container's ID
    24                          - isolation=(`default`|`process`|`hyperv`) (Windows daemon only)
    25                          - is-task=(true|false)
    26                          - label=<key> or label=<key>=<value>
    27                          - name=<string> a container's name
    28                          - network=(<network-id>|<network-name>)
    29                          - publish=(<port>[/<proto>]|<startport-endport>/[<proto>])
    30                          - since=(<container-name>|<container-id>)
    31                          - status=(created|restarting|removing|running|paused|exited)
    32                          - volume=(<volume name>|<mount point destination>)
    33        --format string   Pretty-print containers using a Go template
    34        --help            Print usage
    35    -n, --last int        Show n last created containers (includes all states) (default -1)
    36    -l, --latest          Show the latest created container (includes all states)
    37        --no-trunc        Don't truncate output
    38    -q, --quiet           Only display numeric IDs
    39    -s, --size            Display total file sizes
    40  ```
    41  
    42  ## Examples
    43  
    44  ### Prevent truncating output
    45  
    46  Running `docker ps --no-trunc` showing 2 linked containers.
    47  
    48  ```bash
    49  $ docker ps
    50  
    51  CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
    52  4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds       3300-3310/tcp       webapp
    53  d7886598dbe2        crosbymichael/redis:latest   /redis-server --dir    33 minutes ago       Up 33 minutes       6379/tcp            redis,webapp/db
    54  ```
    55  
    56  ### Show both running and stopped containers
    57  
    58  The `docker ps` command only shows running containers by default. To see all
    59  containers, use the `-a` (or `--all`) flag:
    60  
    61  ```bash
    62  $ docker ps -a
    63  ```
    64  
    65  `docker ps` groups exposed ports into a single range if possible. E.g., a
    66  container that exposes TCP ports `100, 101, 102` displays `100-102/tcp` in
    67  the `PORTS` column.
    68  
    69  ### Show disk usage by container
    70  
    71  The `docker ps -s` command displays two different on-disk-sizes for each container:
    72  
    73  ```bash
    74  $ docker ps -s
    75  
    76  CONTAINER ID   IMAGE          COMMAND                  CREATED        STATUS       PORTS   NAMES        SIZE                                                                                      SIZE
    77  e90b8831a4b8   nginx          "/bin/bash -c 'mkdir "   11 weeks ago   Up 4 hours           my_nginx     35.58 kB (virtual 109.2 MB)
    78  00c6131c5e30   telegraf:1.5   "/entrypoint.sh"         11 weeks ago   Up 11 weeks          my_telegraf  0 B (virtual 209.5 MB)
    79  ```
    80    * The "size" information shows the amount of data (on disk) that is used for the _writable_ layer of each container
    81    * The "virtual size" is the total amount of disk-space used for the read-only _image_ data used by the container and the writable layer.
    82  
    83  For more information, refer to the [container size on disk](https://docs.docker.com/storage/storagedriver/#container-size-on-disk) section.
    84  
    85  
    86  ### Filtering
    87  
    88  The filtering flag (`-f` or `--filter`) format is a `key=value` pair. If there is more
    89  than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`)
    90  
    91  The currently supported filters are:
    92  
    93  | Filter                | Description                                                                                                                          |
    94  |:----------------------|:-------------------------------------------------------------------------------------------------------------------------------------|
    95  | `id`                  | Container's ID                                                                                                                       |
    96  | `name`                | Container's name                                                                                                                     |
    97  | `label`               | An arbitrary string representing either a key or a key-value pair. Expressed as `<key>` or `<key>=<value>`                           |
    98  | `exited`              | An integer representing the container's exit code. Only useful with `--all`.                                                         |
    99  | `status`              | One of `created`, `restarting`, `running`, `removing`, `paused`, `exited`, or `dead`                                                 |
   100  | `ancestor`            | Filters containers which share a given image as an ancestor. Expressed as `<image-name>[:<tag>]`,  `<image id>`, or `<image@digest>` |
   101  | `before` or `since`   | Filters containers created before or after a given container ID or name                                                              |
   102  | `volume`              | Filters running containers which have mounted a given volume or bind mount.                                                          |
   103  | `network`             | Filters running containers connected to a given network.                                                                             |
   104  | `publish` or `expose` | Filters containers which publish or expose a given port. Expressed as `<port>[/<proto>]` or `<startport-endport>/[<proto>]`          |
   105  | `health`              | Filters containers based on their healthcheck status. One of `starting`, `healthy`, `unhealthy` or `none`.                           |
   106  | `isolation`           | Windows daemon only. One of `default`, `process`, or `hyperv`.                                                                       |
   107  | `is-task`             | Filters containers that are a "task" for a service. Boolean option (`true` or `false`)                                               |
   108  
   109  
   110  #### label
   111  
   112  The `label` filter matches containers based on the presence of a `label` alone or a `label` and a
   113  value.
   114  
   115  The following filter matches containers with the `color` label regardless of its value.
   116  
   117  ```bash
   118  $ docker ps --filter "label=color"
   119  
   120  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   121  673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
   122  d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
   123  ```
   124  
   125  The following filter matches containers with the `color` label with the `blue` value.
   126  
   127  ```bash
   128  $ docker ps --filter "label=color=blue"
   129  
   130  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   131  d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
   132  ```
   133  
   134  #### name
   135  
   136  The `name` filter matches on all or part of a container's name.
   137  
   138  The following filter matches all containers with a name containing the `nostalgic_stallman` string.
   139  
   140  ```bash
   141  $ docker ps --filter "name=nostalgic_stallman"
   142  
   143  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   144  9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
   145  ```
   146  
   147  You can also filter for a substring in a name as this shows:
   148  
   149  ```bash
   150  $ docker ps --filter "name=nostalgic"
   151  
   152  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   153  715ebfcee040        busybox             "top"               3 seconds ago       Up 1 second                             i_am_nostalgic
   154  9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
   155  673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
   156  ```
   157  
   158  #### exited
   159  
   160  The `exited` filter matches containers by exist status code. For example, to
   161  filter for containers that have exited successfully:
   162  
   163  ```bash
   164  $ docker ps -a --filter 'exited=0'
   165  
   166  CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
   167  ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
   168  106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
   169  48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
   170  ```
   171  
   172  #### Filter by exit signal
   173  
   174  You can use a filter to locate containers that exited with status of `137`
   175  meaning a `SIGKILL(9)` killed them.
   176  
   177  ```bash
   178  $ docker ps -a --filter 'exited=137'
   179  
   180  CONTAINER ID        IMAGE               COMMAND                CREATED             STATUS                       PORTS               NAMES
   181  b3e1c0ed5bfe        ubuntu:latest       "sleep 1000"           12 seconds ago      Exited (137) 5 seconds ago                       grave_kowalevski
   182  a2eb5558d669        redis:latest        "/entrypoint.sh redi   2 hours ago         Exited (137) 2 hours ago                         sharp_lalande
   183  ```
   184  
   185  Any of these events result in a `137` status:
   186  
   187  * the `init` process of the container is killed manually
   188  * `docker kill` kills the container
   189  * Docker daemon restarts which kills all running containers
   190  
   191  #### status
   192  
   193  The `status` filter matches containers by status. You can filter using
   194  `created`, `restarting`, `running`, `removing`, `paused`, `exited` and `dead`. For example,
   195  to filter for `running` containers:
   196  
   197  ```bash
   198  $ docker ps --filter status=running
   199  
   200  CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
   201  715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
   202  d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
   203  9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
   204  ```
   205  
   206  To filter for `paused` containers:
   207  
   208  ```bash
   209  $ docker ps --filter status=paused
   210  
   211  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
   212  673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
   213  ```
   214  
   215  #### ancestor
   216  
   217  The `ancestor` filter matches containers based on its image or a descendant of
   218  it. The filter supports the following image representation:
   219  
   220  - `image`
   221  - `image:tag`
   222  - `image:tag@digest`
   223  - `short-id`
   224  - `full-id`
   225  
   226  If you don't specify a `tag`, the `latest` tag is used. For example, to filter
   227  for containers that use the latest `ubuntu` image:
   228  
   229  ```bash
   230  $ docker ps --filter ancestor=ubuntu
   231  
   232  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   233  919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   234  5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
   235  82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   236  bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
   237  ```
   238  
   239  Match containers based on the `ubuntu-c1` image which, in this case, is a child
   240  of `ubuntu`:
   241  
   242  ```bash
   243  $ docker ps --filter ancestor=ubuntu-c1
   244  
   245  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   246  919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
   247  ```
   248  
   249  Match containers based on the `ubuntu` version `12.04.5` image:
   250  
   251  ```bash
   252  $ docker ps --filter ancestor=ubuntu:12.04.5
   253  
   254  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   255  82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   256  ```
   257  
   258  The following matches containers based on the layer `d0e008c6cf02` or an image
   259  that have this layer in its layer stack.
   260  
   261  ```bash
   262  $ docker ps --filter ancestor=d0e008c6cf02
   263  
   264  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
   265  82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
   266  ```
   267  
   268  #### Create time
   269  
   270  ##### before
   271  
   272  The `before` filter shows only containers created before the container with
   273  given id or name. For example, having these containers created:
   274  
   275  ```bash
   276  $ docker ps
   277  
   278  CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   279  9c3527ed70ce        busybox     "top"         14 seconds ago       Up 15 seconds                          desperate_dubinsky
   280  4aace5031105        busybox     "top"         48 seconds ago       Up 49 seconds                          focused_hamilton
   281  6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   282  ```
   283  
   284  Filtering with `before` would give:
   285  
   286  ```bash
   287  $ docker ps -f before=9c3527ed70ce
   288  
   289  CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
   290  4aace5031105        busybox     "top"         About a minute ago   Up About a minute                      focused_hamilton
   291  6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
   292  ```
   293  
   294  ##### since
   295  
   296  The `since` filter shows only containers created since the container with given
   297  id or name. For example, with the same containers as in `before` filter:
   298  
   299  ```bash
   300  $ docker ps -f since=6e63f6ff38b0
   301  
   302  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   303  9c3527ed70ce        busybox     "top"         10 minutes ago      Up 10 minutes                           desperate_dubinsky
   304  4aace5031105        busybox     "top"         10 minutes ago      Up 10 minutes                           focused_hamilton
   305  ```
   306  
   307  #### volume
   308  
   309  The `volume` filter shows only containers that mount a specific volume or have
   310  a volume mounted in a specific path:
   311  
   312  ```bash
   313  $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
   314  
   315  CONTAINER ID        MOUNTS
   316  9c3527ed70ce        remote-volume
   317  
   318  $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
   319  
   320  CONTAINER ID        MOUNTS
   321  9c3527ed70ce        remote-volume
   322  ```
   323  
   324  #### network
   325  
   326  The `network` filter shows only containers that are connected to a network with
   327  a given name or id.
   328  
   329  The following filter matches all containers that are connected to a network
   330  with a name containing `net1`.
   331  
   332  ```bash
   333  $ docker run -d --net=net1 --name=test1 ubuntu top
   334  $ docker run -d --net=net2 --name=test2 ubuntu top
   335  
   336  $ docker ps --filter network=net1
   337  
   338  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   339  9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
   340  ```
   341  
   342  The network filter matches on both the network's name and id. The following
   343  example shows all containers that are attached to the `net1` network, using
   344  the network id as a filter;
   345  
   346  ```bash
   347  $ docker network inspect --format "{{.ID}}" net1
   348  
   349  8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
   350  
   351  $ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
   352  
   353  CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
   354  9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
   355  ```
   356  
   357  #### publish and expose
   358  
   359  The `publish` and `expose` filters show only containers that have published or exposed port with a given port
   360  number, port range, and/or protocol. The default protocol is `tcp` when not specified.
   361  
   362  The following filter matches all containers that have published port of 80:
   363  
   364  ```bash
   365  $ docker run -d --publish=80 busybox top
   366  $ docker run -d --expose=8080 busybox top
   367  
   368  $ docker ps -a
   369  
   370  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                   NAMES
   371  9833437217a5        busybox             "top"               5 seconds ago       Up 4 seconds        8080/tcp                dreamy_mccarthy
   372  fc7e477723b7        busybox             "top"               50 seconds ago      Up 50 seconds       0.0.0.0:32768->80/tcp   admiring_roentgen
   373  
   374  $ docker ps --filter publish=80
   375  
   376  CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS                   NAMES
   377  fc7e477723b7        busybox             "top"               About a minute ago   Up About a minute   0.0.0.0:32768->80/tcp   admiring_roentgen
   378  ```
   379  
   380  The following filter matches all containers that have exposed TCP port in the range of `8000-8080`:
   381  ```bash
   382  $ docker ps --filter expose=8000-8080/tcp
   383  
   384  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   385  9833437217a5        busybox             "top"               21 seconds ago      Up 19 seconds       8080/tcp            dreamy_mccarthy
   386  ```
   387  
   388  The following filter matches all containers that have exposed UDP port `80`:
   389  ```bash
   390  $ docker ps --filter publish=80/udp
   391  
   392  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
   393  ```
   394  
   395  ### Formatting
   396  
   397  The formatting option (`--format`) pretty-prints container output using a Go
   398  template.
   399  
   400  Valid placeholders for the Go template are listed below:
   401  
   402  | Placeholder   | Description                                                                                     |
   403  |:--------------|:------------------------------------------------------------------------------------------------|
   404  | `.ID`         | Container ID                                                                                    |
   405  | `.Image`      | Image ID                                                                                        |
   406  | `.Command`    | Quoted command                                                                                  |
   407  | `.CreatedAt`  | Time when the container was created.                                                            |
   408  | `.RunningFor` | Elapsed time since the container was started.                                                   |
   409  | `.Ports`      | Exposed ports.                                                                                  |
   410  | `.State`      | Container status (for example; "created", "running", "exited").                                 |
   411  | `.Status`     | Container status with details about duration and health-status.                                 |
   412  | `.Size`       | Container disk size.                                                                            |
   413  | `.Names`      | Container names.                                                                                |
   414  | `.Labels`     | All labels assigned to the container.                                                           |
   415  | `.Label`      | Value of a specific label for this container. For example `'{{.Label "com.docker.swarm.cpu"}}'` |
   416  | `.Mounts`     | Names of the volumes mounted in this container.                                                 |
   417  | `.Networks`   | Names of the networks attached to this container.                                               |
   418  
   419  When using the `--format` option, the `ps` command will either output the data
   420  exactly as the template declares or, when using the `table` directive, includes
   421  column headers as well.
   422  
   423  The following example uses a template without headers and outputs the `ID` and
   424  `Command` entries separated by a colon (`:`) for all running containers:
   425  
   426  ```bash
   427  $ docker ps --format "{{.ID}}: {{.Command}}"
   428  
   429  a87ecb4f327c: /bin/sh -c #(nop) MA
   430  01946d9d34d8: /bin/sh -c #(nop) MA
   431  c1d3b0166030: /bin/sh -c yum -y up
   432  41d50ecd2f57: /bin/sh -c #(nop) MA
   433  ```
   434  
   435  To list all running containers with their labels in a table format you can use:
   436  
   437  ```bash
   438  $ docker ps --format "table {{.ID}}\t{{.Labels}}"
   439  
   440  CONTAINER ID        LABELS
   441  a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
   442  01946d9d34d8
   443  c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
   444  41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
   445  ```