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