github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/container_ls.md (about) 1 # ps 2 3 <!---MARKER_GEN_START--> 4 List 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 30 Running `docker ps --no-trunc` showing 2 linked containers. 31 32 ```console 33 $ docker ps --no-trunc 34 35 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 36 ca5534a51dd04bbcebe9b23ba05f389466cf0c190f1f8f182d7eea92a9671d00 ubuntu:22.04 bash 17 seconds ago Up 16 seconds 3300-3310/tcp webapp 37 9ca9747b233100676a48cc7806131586213fa5dab86dd1972d6a8732e3a84a4d 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 42 The `docker ps` command only shows running containers by default. To see all 43 containers, 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 50 container that exposes TCP ports `100, 101, 102` displays `100-102/tcp` in 51 the `PORTS` column. 52 53 ### <a name="size"></a> Show disk usage by container (--size) 54 55 The `docker ps --size` (or `-s`) command displays two different on-disk-sizes for each container: 56 57 ```console 58 $ docker ps --size 59 60 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 61 e90b8831a4b8 nginx "/bin/bash -c 'mkdir " 11 weeks ago Up 4 hours my_nginx 35.58 kB (virtual 109.2 MB) 62 00c6131c5e30 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 67 For 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 72 The `--filter` (or `-f`) flag format is a `key=value` pair. If there is more 73 than one filter, then pass multiple flags (e.g. `--filter "foo=bar" --filter "bif=baz"`). 74 75 The 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 96 The `label` filter matches containers based on the presence of a `label` alone or a `label` and a 97 value. 98 99 The following filter matches containers with the `color` label regardless of its value. 100 101 ```console 102 $ docker ps --filter "label=color" 103 104 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 105 673394ef1d4c busybox "top" 47 seconds ago Up 45 seconds nostalgic_shockley 106 d85756f57265 busybox "top" 52 seconds ago Up 51 seconds high_albattani 107 ``` 108 109 The following filter matches containers with the `color` label with the `blue` value. 110 111 ```console 112 $ docker ps --filter "label=color=blue" 113 114 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 115 d85756f57265 busybox "top" About a minute ago Up About a minute high_albattani 116 ``` 117 118 #### name 119 120 The `name` filter matches on all or part of a container's name. 121 122 The following filter matches all containers with a name containing the `nostalgic_stallman` string. 123 124 ```console 125 $ docker ps --filter "name=nostalgic_stallman" 126 127 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 128 9b6247364a03 busybox "top" 2 minutes ago Up 2 minutes nostalgic_stallman 129 ``` 130 131 You can also filter for a substring in a name as this shows: 132 133 ```console 134 $ docker ps --filter "name=nostalgic" 135 136 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 137 715ebfcee040 busybox "top" 3 seconds ago Up 1 second i_am_nostalgic 138 9b6247364a03 busybox "top" 7 minutes ago Up 7 minutes nostalgic_stallman 139 673394ef1d4c busybox "top" 38 minutes ago Up 38 minutes nostalgic_shockley 140 ``` 141 142 #### exited 143 144 The `exited` filter matches containers by exist status code. For example, to 145 filter for containers that have exited successfully: 146 147 ```console 148 $ docker ps -a --filter 'exited=0' 149 150 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 151 ea09c3c82f6e registry:latest /srv/run.sh 2 weeks ago Exited (0) 2 weeks ago 127.0.0.1:5000->5000/tcp desperate_leakey 152 106ea823fe4e fedora:latest /bin/sh -c 'bash -l' 2 weeks ago Exited (0) 2 weeks ago determined_albattani 153 48ee228c9464 fedora:20 bash 2 weeks ago Exited (0) 2 weeks ago tender_torvalds 154 ``` 155 156 #### Filter by exit signal 157 158 You can use a filter to locate containers that exited with status of `137` 159 meaning a `SIGKILL(9)` killed them. 160 161 ```console 162 $ docker ps -a --filter 'exited=137' 163 164 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 165 b3e1c0ed5bfe ubuntu:latest "sleep 1000" 12 seconds ago Exited (137) 5 seconds ago grave_kowalevski 166 a2eb5558d669 redis:latest "/entrypoint.sh redi 2 hours ago Exited (137) 2 hours ago sharp_lalande 167 ``` 168 169 Any 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 177 The `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 189 For example, to filter for `running` containers: 190 191 ```console 192 $ docker ps --filter status=running 193 194 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 195 715ebfcee040 busybox "top" 16 minutes ago Up 16 minutes i_am_nostalgic 196 d5c976d3c462 busybox "top" 23 minutes ago Up 23 minutes top 197 9b6247364a03 busybox "top" 24 minutes ago Up 24 minutes nostalgic_stallman 198 ``` 199 200 To filter for `paused` containers: 201 202 ```console 203 $ docker ps --filter status=paused 204 205 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 206 673394ef1d4c busybox "top" About an hour ago Up About an hour (Paused) nostalgic_shockley 207 ``` 208 209 #### ancestor 210 211 The `ancestor` filter matches containers based on its image or a descendant of 212 it. The filter supports the following image representation: 213 214 - `image` 215 - `image:tag` 216 - `image:tag@digest` 217 - `short-id` 218 - `full-id` 219 220 If you don't specify a `tag`, the `latest` tag is used. For example, to filter 221 for containers that use the latest `ubuntu` image: 222 223 ```console 224 $ docker ps --filter ancestor=ubuntu 225 226 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 227 919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace 228 5d1e4a540723 ubuntu-c2 "top" About a minute ago Up About a minute admiring_sammet 229 82a598284012 ubuntu "top" 3 minutes ago Up 3 minutes sleepy_bose 230 bab2a34ba363 ubuntu "top" 3 minutes ago Up 3 minutes focused_yonath 231 ``` 232 233 Match containers based on the `ubuntu-c1` image which, in this case, is a child 234 of `ubuntu`: 235 236 ```console 237 $ docker ps --filter ancestor=ubuntu-c1 238 239 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 240 919e1179bdb8 ubuntu-c1 "top" About a minute ago Up About a minute admiring_lovelace 241 ``` 242 243 Match containers based on the `ubuntu` version `22.04` image: 244 245 ```console 246 $ docker ps --filter ancestor=ubuntu:22.04 247 248 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 249 82a598284012 ubuntu:22.04 "top" 3 minutes ago Up 3 minutes sleepy_bose 250 ``` 251 252 The following matches containers based on the layer `d0e008c6cf02` or an image 253 that have this layer in its layer stack. 254 255 ```console 256 $ docker ps --filter ancestor=d0e008c6cf02 257 258 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 259 82a598284012 ubuntu:22.04 "top" 3 minutes ago Up 3 minutes sleepy_bose 260 ``` 261 262 #### Create time 263 264 ##### before 265 266 The `before` filter shows only containers created before the container with 267 a given ID or name. For example, having these containers created: 268 269 ```console 270 $ docker ps 271 272 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 273 9c3527ed70ce busybox "top" 14 seconds ago Up 15 seconds desperate_dubinsky 274 4aace5031105 busybox "top" 48 seconds ago Up 49 seconds focused_hamilton 275 6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat 276 ``` 277 278 Filtering with `before` would give: 279 280 ```console 281 $ docker ps -f before=9c3527ed70ce 282 283 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 284 4aace5031105 busybox "top" About a minute ago Up About a minute focused_hamilton 285 6e63f6ff38b0 busybox "top" About a minute ago Up About a minute distracted_fermat 286 ``` 287 288 ##### since 289 290 The `since` filter shows only containers created since the container with a given 291 ID or name. For example, with the same containers as in `before` filter: 292 293 ```console 294 $ docker ps -f since=6e63f6ff38b0 295 296 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 297 9c3527ed70ce busybox "top" 10 minutes ago Up 10 minutes desperate_dubinsky 298 4aace5031105 busybox "top" 10 minutes ago Up 10 minutes focused_hamilton 299 ``` 300 301 #### volume 302 303 The `volume` filter shows only containers that mount a specific volume or have 304 a volume mounted in a specific path: 305 306 ```console 307 $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}" 308 309 CONTAINER ID MOUNTS 310 9c3527ed70ce remote-volume 311 312 $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" 313 314 CONTAINER ID MOUNTS 315 9c3527ed70ce remote-volume 316 ``` 317 318 #### network 319 320 The `network` filter shows only containers that are connected to a network with 321 a given name or ID. 322 323 The following filter matches all containers that are connected to a network 324 with 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 332 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 333 9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 334 ``` 335 336 The network filter matches on both the network's name and ID. The following 337 example shows all containers that are attached to the `net1` network, using 338 the network ID as a filter: 339 340 ```console 341 $ docker network inspect --format "{{.ID}}" net1 342 343 8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 344 345 $ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5 346 347 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 348 9d4893ed80fe ubuntu "top" 10 minutes ago Up 10 minutes test1 349 ``` 350 351 #### publish and expose 352 353 The `publish` and `expose` filters show only containers that have published or exposed port with a given port 354 number, port range, and/or protocol. The default protocol is `tcp` when not specified. 355 356 The 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 364 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 365 9833437217a5 busybox "top" 5 seconds ago Up 4 seconds 8080/tcp dreamy_mccarthy 366 fc7e477723b7 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 370 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 371 fc7e477723b7 busybox "top" About a minute ago Up About a minute 0.0.0.0:32768->80/tcp admiring_roentgen 372 ``` 373 374 The 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 379 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 380 9833437217a5 busybox "top" 21 seconds ago Up 19 seconds 8080/tcp dreamy_mccarthy 381 ``` 382 383 The following filter matches all containers that have exposed UDP port `80`: 384 385 ```console 386 $ docker ps --filter publish=80/udp 387 388 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 389 ``` 390 391 ### <a name="format"></a> Format the output (--format) 392 393 The formatting option (`--format`) pretty-prints container output using a Go 394 template. 395 396 Valid 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 415 When using the `--format` option, the `ps` command will either output the data 416 exactly as the template declares or, when using the `table` directive, includes 417 column headers as well. 418 419 The 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 425 a87ecb4f327c: /bin/sh -c #(nop) MA 426 01946d9d34d8: /bin/sh -c #(nop) MA 427 c1d3b0166030: /bin/sh -c yum -y up 428 41d50ecd2f57: /bin/sh -c #(nop) MA 429 ``` 430 431 To 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 436 CONTAINER ID LABELS 437 a87ecb4f327c com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd 438 01946d9d34d8 439 c1d3b0166030 com.docker.swarm.node=debian,com.docker.swarm.cpu=6 440 41d50ecd2f57 com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd 441 ``` 442 443 To 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 ```