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