@@ -8,21 +8,110 @@ List containers
8
8
| Name | Type | Default | Description |
9
9
| --- | --- | --- | --- |
10
10
| ` -a ` , ` --all ` | | | Show all stopped containers (including those created by the run command) |
11
- | ` --format ` | ` string ` | ` pretty ` | Format the output. Values: [ pretty \| json] |
11
+ | [ ` --filter ` ] ( #filter ) | ` string ` | | Filter services by a property (supported filters: status). |
12
+ | [ ` --format ` ] ( #format ) | ` string ` | ` pretty ` | Format the output. Values: [ pretty \| json] |
12
13
| ` -q ` , ` --quiet ` | | | Only display IDs |
13
14
| ` --services ` | | | Display services |
14
- | ` --status ` | ` stringArray ` | | Filter services by status. Values: [ paused \| restarting \| removing \| running \| dead \| created \| exited] |
15
+ | [ ` --status ` ] ( #status ) | ` stringArray ` | | Filter services by status. Values: [ paused \| restarting \| removing \| running \| dead \| created \| exited] |
15
16
16
17
17
18
<!-- -MARKER_GEN_END-->
18
19
19
20
## Description
20
21
21
22
Lists containers for a Compose project, with current status and exposed ports.
23
+ By default, both running and stopped containers are shown:
22
24
23
25
``` console
24
26
$ docker compose ps
25
- NAME SERVICE STATUS PORTS
26
- example_foo_1 foo running (healthy) 0.0.0.0:8000->80/tcp
27
- example_bar_1 bar exited (1)
27
+ NAME COMMAND SERVICE STATUS PORTS
28
+ example-bar-1 "/docker-entrypoint.…" bar exited (0)
29
+ example-foo-1 "/docker-entrypoint.…" foo running 0.0.0.0:8080->80/tcp
28
30
```
31
+
32
+ ## Examples
33
+
34
+ ### <a name =" format " ></a > Format the output (--format)
35
+
36
+ By default, the ` docker compose ps ` command uses a table ("pretty") format to
37
+ show the containers. The ` --format ` flag allows you to specify alternative
38
+ presentations for the output. Currently supported options are ` pretty ` (default),
39
+ and ` json ` , which outputs information about the containers as a JSON array:
40
+
41
+ ``` console
42
+ $ docker compose ps --format json
43
+ [{"ID":"1553b0236cf4d2715845f053a4ee97042c4f9a2ef655731ee34f1f7940eaa41a","Name":"example-bar-1","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Project":"example","Service":"bar","State":"exited","Health":"","ExitCode":0,"Publishers":null},{"ID":"f02a4efaabb67416e1ff127d51c4b5578634a0ad5743bd65225ff7d1909a3fa0","Name":"example-foo-1","Command":"/docker-entrypoint.sh nginx -g 'daemon off;'","Project":"example","Service":"foo","State":"running","Health":"","ExitCode":0,"Publishers":[{"URL":"0.0.0.0","TargetPort":80,"PublishedPort":8080,"Protocol":"tcp"}]}]
44
+ ```
45
+
46
+ The JSON output allows you to use the information in other tools for further
47
+ processing, for example, using the [ ` jq ` utility] ( https://stedolan.github.io/jq/ ) {: target ="_ blank" rel="noopener" class="_ "}
48
+ to pretty-print the JSON:
49
+
50
+ ``` console
51
+ $ docker compose ps --format json | jq .
52
+ [
53
+ {
54
+ "ID": "1553b0236cf4d2715845f053a4ee97042c4f9a2ef655731ee34f1f7940eaa41a",
55
+ "Name": "example-bar-1",
56
+ "Command": "/docker-entrypoint.sh nginx -g 'daemon off;'",
57
+ "Project": "example",
58
+ "Service": "bar",
59
+ "State": "exited",
60
+ "Health": "",
61
+ "ExitCode": 0,
62
+ "Publishers": null
63
+ },
64
+ {
65
+ "ID": "f02a4efaabb67416e1ff127d51c4b5578634a0ad5743bd65225ff7d1909a3fa0",
66
+ "Name": "example-foo-1",
67
+ "Command": "/docker-entrypoint.sh nginx -g 'daemon off;'",
68
+ "Project": "example",
69
+ "Service": "foo",
70
+ "State": "running",
71
+ "Health": "",
72
+ "ExitCode": 0,
73
+ "Publishers": [
74
+ {
75
+ "URL": "0.0.0.0",
76
+ "TargetPort": 80,
77
+ "PublishedPort": 8080,
78
+ "Protocol": "tcp"
79
+ }
80
+ ]
81
+ }
82
+ ]
83
+ ```
84
+
85
+ ### <a name =" status " ></a > Filter containers by status (--status)
86
+
87
+ Use the ` --status ` flag to filter the list of containers by status. For example,
88
+ to show only containers that are running, or only containers that have exited:
89
+
90
+ ``` console
91
+ $ docker compose ps --status=running
92
+ NAME COMMAND SERVICE STATUS PORTS
93
+ example-foo-1 "/docker-entrypoint.…" foo running 0.0.0.0:8080->80/tcp
94
+
95
+ $ docker compose ps --status=exited
96
+ NAME COMMAND SERVICE STATUS PORTS
97
+ example-bar-1 "/docker-entrypoint.…" bar exited (0)
98
+ ```
99
+
100
+ ### <a name =" filter " ></a > Filter containers by status (--filter)
101
+
102
+ The [ ` --status ` flag] ( #status ) is a convenience shorthand for the ` --filter status=<status> `
103
+ flag. The example below is the equivalent to the example from the previous section,
104
+ this time using the ` --filter ` flag:
105
+
106
+ ``` console
107
+ $ docker compose ps --filter status=running
108
+ NAME COMMAND SERVICE STATUS PORTS
109
+ example-foo-1 "/docker-entrypoint.…" foo running 0.0.0.0:8080->80/tcp
110
+
111
+ $ docker compose ps --filter status=running
112
+ NAME COMMAND SERVICE STATUS PORTS
113
+ example-bar-1 "/docker-entrypoint.…" bar exited (0)
114
+ ```
115
+
116
+ The ` docker compose ps ` command currently only supports the ` --filter status=<status> `
117
+ option, but additional filter options may be added in future.
0 commit comments