...

Text file src/github.com/docker/cli/docs/reference/commandline/container_ls.md

Documentation: github.com/docker/cli/docs/reference/commandline

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

View as plain text