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