Browse code

docs: improve formatting and highlighting of docker ps reference

this improves the formatting, and code-highlighting
of the `docker ps` reference page, and wraps sentences
to 80 chars

also adds single quotes around the formatting
example for labels.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2016/07/21 19:27:39
Showing 1 changed files
... ...
@@ -38,15 +38,24 @@ Options:
38 38
 
39 39
 Running `docker ps --no-trunc` showing 2 linked containers.
40 40
 
41
-    $ docker ps
42
-    CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
43
-    4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds       3300-3310/tcp       webapp
44
-    d7886598dbe2        crosbymichael/redis:latest   /redis-server --dir    33 minutes ago       Up 33 minutes       6379/tcp            redis,webapp/db
41
+```bash
42
+$ docker ps
43
+
44
+CONTAINER ID        IMAGE                        COMMAND                CREATED              STATUS              PORTS               NAMES
45
+4c01db0b339c        ubuntu:12.04                 bash                   17 seconds ago       Up 16 seconds       3300-3310/tcp       webapp
46
+d7886598dbe2        crosbymichael/redis:latest   /redis-server --dir    33 minutes ago       Up 33 minutes       6379/tcp            redis,webapp/db
47
+```
48
+
49
+The `docker ps` command only shows running containers by default. To see all
50
+containers, use the `-a` (or `--all`) flag:
45 51
 
46
-`docker ps` will show only running containers by default. To see all containers:
47
-`docker ps -a`
52
+```bash
53
+$ docker ps -a
54
+```
48 55
 
49
-`docker ps` will group exposed ports into a single range if possible. E.g., a container that exposes TCP ports `100, 101, 102` will display `100-102/tcp` in the `PORTS` column.
56
+`docker ps` groups exposed ports into a single range if possible. E.g., a
57
+container that exposes TCP ports `100, 101, 102` displays `100-102/tcp` in
58
+the `PORTS` column.
50 59
 
51 60
 ## Filtering
52 61
 
... ...
@@ -74,16 +83,22 @@ value.
74 74
 
75 75
 The following filter matches containers with the `color` label regardless of its value.
76 76
 
77
-    $ docker ps --filter "label=color"
78
-    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
79
-    673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
80
-    d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
77
+```bash
78
+$ docker ps --filter "label=color"
79
+
80
+CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
81
+673394ef1d4c        busybox             "top"               47 seconds ago      Up 45 seconds                           nostalgic_shockley
82
+d85756f57265        busybox             "top"               52 seconds ago      Up 51 seconds                           high_albattani
83
+```
81 84
 
82 85
 The following filter matches containers with the `color` label with the `blue` value.
83 86
 
84
-    $ docker ps --filter "label=color=blue"
85
-    CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
86
-    d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
87
+```bash
88
+$ docker ps --filter "label=color=blue"
89
+
90
+CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
91
+d85756f57265        busybox             "top"               About a minute ago   Up About a minute                       high_albattani
92
+```
87 93
 
88 94
 #### Name
89 95
 
... ...
@@ -91,49 +106,66 @@ The `name` filter matches on all or part of a container's name.
91 91
 
92 92
 The following filter matches all containers with a name containing the `nostalgic_stallman` string.
93 93
 
94
-    $ docker ps --filter "name=nostalgic_stallman"
95
-    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
96
-    9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
94
+```bash
95
+$ docker ps --filter "name=nostalgic_stallman"
96
+
97
+CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
98
+9b6247364a03        busybox             "top"               2 minutes ago       Up 2 minutes                            nostalgic_stallman
99
+```
97 100
 
98 101
 You can also filter for a substring in a name as this shows:
99 102
 
100
-    $ docker ps --filter "name=nostalgic"
101
-    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
102
-    715ebfcee040        busybox             "top"               3 seconds ago       Up 1 seconds                            i_am_nostalgic
103
-    9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
104
-    673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
103
+```bash
104
+$ docker ps --filter "name=nostalgic"
105
+
106
+CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
107
+715ebfcee040        busybox             "top"               3 seconds ago       Up 1 seconds                            i_am_nostalgic
108
+9b6247364a03        busybox             "top"               7 minutes ago       Up 7 minutes                            nostalgic_stallman
109
+673394ef1d4c        busybox             "top"               38 minutes ago      Up 38 minutes                           nostalgic_shockley
110
+```
105 111
 
106 112
 #### Exited
107 113
 
108
-The `exited` filter matches containers by exist status code. For example, to filter for containers
109
-that have exited successfully:
114
+The `exited` filter matches containers by exist status code. For example, to
115
+filter for containers that have exited successfully:
116
+
117
+```bash
118
+$ docker ps -a --filter 'exited=0'
110 119
 
111
-    $ docker ps -a --filter 'exited=0'
112
-    CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
113
-    ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
114
-    106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
115
-    48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
120
+CONTAINER ID        IMAGE             COMMAND                CREATED             STATUS                   PORTS                      NAMES
121
+ea09c3c82f6e        registry:latest   /srv/run.sh            2 weeks ago         Exited (0) 2 weeks ago   127.0.0.1:5000->5000/tcp   desperate_leakey
122
+106ea823fe4e        fedora:latest     /bin/sh -c 'bash -l'   2 weeks ago         Exited (0) 2 weeks ago                              determined_albattani
123
+48ee228c9464        fedora:20         bash                   2 weeks ago         Exited (0) 2 weeks ago                              tender_torvalds
124
+```
116 125
 
117 126
 #### Status
118 127
 
119
-The `status` filter matches containers by status. You can filter using `created`, `restarting`, `running`, `paused`, `exited` and `dead`. For example, to filter for `running` containers:
128
+The `status` filter matches containers by status. You can filter using
129
+`created`, `restarting`, `running`, `paused`, `exited` and `dead`. For example,
130
+to filter for `running` containers:
131
+
132
+```bash
133
+$ docker ps --filter status=running
120 134
 
121
-    $ docker ps --filter status=running
122
-    CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
123
-    715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
124
-    d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
125
-    9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
135
+CONTAINER ID        IMAGE                  COMMAND             CREATED             STATUS              PORTS               NAMES
136
+715ebfcee040        busybox                "top"               16 minutes ago      Up 16 minutes                           i_am_nostalgic
137
+d5c976d3c462        busybox                "top"               23 minutes ago      Up 23 minutes                           top
138
+9b6247364a03        busybox                "top"               24 minutes ago      Up 24 minutes                           nostalgic_stallman
139
+```
126 140
 
127 141
 To filter for `paused` containers:
128 142
 
129
-    $ docker ps --filter status=paused
130
-    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
131
-    673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
143
+```bash
144
+$ docker ps --filter status=paused
145
+
146
+CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
147
+673394ef1d4c        busybox             "top"               About an hour ago   Up About an hour (Paused)                       nostalgic_shockley
148
+```
132 149
 
133 150
 #### Ancestor
134 151
 
135
-The `ancestor` filter matches containers based on its image or a descendant of it. The filter supports the
136
-following image representation:
152
+The `ancestor` filter matches containers based on its image or a descendant of
153
+it. The filter supports the following image representation:
137 154
 
138 155
 - image
139 156
 - image:tag
... ...
@@ -141,74 +173,99 @@ following image representation:
141 141
 - short-id
142 142
 - full-id
143 143
 
144
-If you don't specify a `tag`, the `latest` tag is used. For example, to filter for containers that use the
145
-latest `ubuntu` image:
144
+If you don't specify a `tag`, the `latest` tag is used. For example, to filter
145
+for containers that use the latest `ubuntu` image:
146
+
147
+```bash
148
+$ docker ps --filter ancestor=ubuntu
146 149
 
147
-    $ docker ps --filter ancestor=ubuntu
148
-    CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
149
-    919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
150
-    5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
151
-    82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
152
-    bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
150
+CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
151
+919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
152
+5d1e4a540723        ubuntu-c2           "top"               About a minute ago   Up About a minute                       admiring_sammet
153
+82a598284012        ubuntu              "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
154
+bab2a34ba363        ubuntu              "top"               3 minutes ago        Up 3 minutes                            focused_yonath
155
+```
153 156
 
154
-Match containers based on the `ubuntu-c1` image which, in this case, is a child of `ubuntu`:
157
+Match containers based on the `ubuntu-c1` image which, in this case, is a child
158
+of `ubuntu`:
155 159
 
156
-    $ docker ps --filter ancestor=ubuntu-c1
157
-    CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
158
-    919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
160
+```bash
161
+$ docker ps --filter ancestor=ubuntu-c1
162
+
163
+CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
164
+919e1179bdb8        ubuntu-c1           "top"               About a minute ago   Up About a minute                       admiring_lovelace
165
+```
159 166
 
160 167
 Match containers based on the `ubuntu` version `12.04.5` image:
161 168
 
162
-    $ docker ps --filter ancestor=ubuntu:12.04.5
163
-    CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
164
-    82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
169
+```bash
170
+$ docker ps --filter ancestor=ubuntu:12.04.5
171
+
172
+CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
173
+82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
174
+```
175
+
176
+The following matches containers based on the layer `d0e008c6cf02` or an image
177
+that have this layer in it's layer stack.
165 178
 
166
-The following matches containers based on the layer `d0e008c6cf02` or an image that have this layer
167
-in it's layer stack.
179
+```bash
180
+$ docker ps --filter ancestor=d0e008c6cf02
168 181
 
169
-    $ docker ps --filter ancestor=d0e008c6cf02
170
-    CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
171
-    82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
182
+CONTAINER ID        IMAGE               COMMAND             CREATED              STATUS              PORTS               NAMES
183
+82a598284012        ubuntu:12.04.5      "top"               3 minutes ago        Up 3 minutes                            sleepy_bose
184
+```
172 185
 
173 186
 #### Before
174 187
 
175
-The `before` filter shows only containers created before the container with given id or name. For example, 
176
-having these containers created:
188
+The `before` filter shows only containers created before the container with
189
+given id or name. For example, having these containers created:
190
+
191
+```bash
192
+$ docker ps
177 193
 
178
-    $ docker ps
179
-    CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
180
-    9c3527ed70ce        busybox     "top"         14 seconds ago       Up 15 seconds                          desperate_dubinsky
181
-    4aace5031105        busybox     "top"         48 seconds ago       Up 49 seconds                          focused_hamilton
182
-    6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
194
+CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
195
+9c3527ed70ce        busybox     "top"         14 seconds ago       Up 15 seconds                          desperate_dubinsky
196
+4aace5031105        busybox     "top"         48 seconds ago       Up 49 seconds                          focused_hamilton
197
+6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
198
+```
183 199
 
184 200
 Filtering with `before` would give:
185 201
 
186
-    $ docker ps -f before=9c3527ed70ce
187
-    CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
188
-    4aace5031105        busybox     "top"         About a minute ago   Up About a minute                      focused_hamilton
189
-    6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
202
+```bash
203
+$ docker ps -f before=9c3527ed70ce
204
+
205
+CONTAINER ID        IMAGE       COMMAND       CREATED              STATUS              PORTS              NAMES
206
+4aace5031105        busybox     "top"         About a minute ago   Up About a minute                      focused_hamilton
207
+6e63f6ff38b0        busybox     "top"         About a minute ago   Up About a minute                      distracted_fermat
208
+```
190 209
 
191 210
 #### Since
192 211
 
193
-The `since` filter shows only containers created since the container with given id or name. For example,
194
-with the same containers as in `before` filter:
212
+The `since` filter shows only containers created since the container with given
213
+id or name. For example, with the same containers as in `before` filter:
195 214
 
196
-    $ docker ps -f since=6e63f6ff38b0
197
-    CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
198
-    9c3527ed70ce        busybox     "top"         10 minutes ago      Up 10 minutes                           desperate_dubinsky
199
-    4aace5031105        busybox     "top"         10 minutes ago      Up 10 minutes                           focused_hamilton
215
+```bash
216
+$ docker ps -f since=6e63f6ff38b0
217
+
218
+CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
219
+9c3527ed70ce        busybox     "top"         10 minutes ago      Up 10 minutes                           desperate_dubinsky
220
+4aace5031105        busybox     "top"         10 minutes ago      Up 10 minutes                           focused_hamilton
221
+```
200 222
 
201 223
 #### Volume
202 224
 
203
-The `volume` filter shows only containers that mount a specific volume or have a volume mounted in a specific path:
225
+The `volume` filter shows only containers that mount a specific volume or have
226
+a volume mounted in a specific path:
204 227
 
205
-    $ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
206
-    CONTAINER ID        MOUNTS
207
-    9c3527ed70ce        remote-volume
228
+```bash
229
+$ docker ps --filter volume=remote-volume --format "table {{.ID}}\t{{.Mounts}}"
230
+CONTAINER ID        MOUNTS
231
+9c3527ed70ce        remote-volume
208 232
 
209
-    $ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
210
-    CONTAINER ID        MOUNTS
211
-    9c3527ed70ce        remote-volume
233
+$ docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}"
234
+CONTAINER ID        MOUNTS
235
+9c3527ed70ce        remote-volume
236
+```
212 237
 
213 238
 #### Network
214 239
 
... ...
@@ -223,6 +280,7 @@ $ docker run -d --net=net1 --name=test1 ubuntu top
223 223
 $ docker run -d --net=net2 --name=test2 ubuntu top
224 224
 
225 225
 $ docker ps --filter network=net1
226
+
226 227
 CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
227 228
 9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
228 229
 ```
... ...
@@ -233,51 +291,61 @@ the network id as a filter;
233 233
 
234 234
 ```bash
235 235
 $ docker network inspect --format "{{.ID}}" net1
236
+
236 237
 8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
237 238
 
238 239
 $ docker ps --filter network=8c0b4110ae930dbe26b258de9bc34a03f98056ed6f27f991d32919bfe401d7c5
240
+
239 241
 CONTAINER ID        IMAGE       COMMAND       CREATED             STATUS              PORTS               NAMES
240 242
 9d4893ed80fe        ubuntu      "top"         10 minutes ago      Up 10 minutes                           test1
241 243
 ```
242 244
 
243 245
 ## Formatting
244 246
 
245
-The formatting option (`--format`) will pretty-print container output using a Go template.
247
+The formatting option (`--format`) pretty-prints container output using a Go
248
+template.
246 249
 
247 250
 Valid placeholders for the Go template are listed below:
248 251
 
249
-Placeholder | Description
250
-`.ID` | Container ID
251
-`.Image` | Image ID
252
-`.Command` | Quoted command
253
-`.CreatedAt` | Time when the container was created.
252
+Placeholder   | Description
253
+--------------|----------------------------------------------------------------------------------------------------
254
+`.ID`         | Container ID
255
+`.Image`      | Image ID
256
+`.Command`    | Quoted command
257
+`.CreatedAt`  | Time when the container was created.
254 258
 `.RunningFor` | Elapsed time since the container was started.
255
-`.Ports` | Exposed ports.
256
-`.Status` | Container status.
257
-`.Size` | Container disk size.
258
-`.Names` | Container names.
259
-`.Labels` | All labels assigned to the container.
260
-`.Label` | Value of a specific label for this container. For example `{{.Label "com.docker.swarm.cpu"}}`
261
-`.Mounts` | Names of the volumes mounted in this container.
262
-
263
-When using the `--format` option, the `ps` command will either output the data exactly as the template
264
-declares or, when using the `table` directive, will include column headers as well.
265
-
266
-The following example uses a template without headers and outputs the `ID` and `Command`
267
-entries separated by a colon for all running containers:
268
-
269
-    $ docker ps --format "{{.ID}}: {{.Command}}"
270
-    a87ecb4f327c: /bin/sh -c #(nop) MA
271
-    01946d9d34d8: /bin/sh -c #(nop) MA
272
-    c1d3b0166030: /bin/sh -c yum -y up
273
-    41d50ecd2f57: /bin/sh -c #(nop) MA
259
+`.Ports`      | Exposed ports.
260
+`.Status`     | Container status.
261
+`.Size`       | Container disk size.
262
+`.Names`      | Container names.
263
+`.Labels`     | All labels assigned to the container.
264
+`.Label`      | Value of a specific label for this container. For example `'{{.Label "com.docker.swarm.cpu"}}'`
265
+`.Mounts`     | Names of the volumes mounted in this container.
266
+
267
+When using the `--format` option, the `ps` command will either output the data
268
+exactly as the template declares or, when using the `table` directive, includes
269
+column headers as well.
270
+
271
+The following example uses a template without headers and outputs the `ID` and
272
+`Command` entries separated by a colon for all running containers:
273
+
274
+```bash
275
+$ docker ps --format "{{.ID}}: {{.Command}}"
276
+
277
+a87ecb4f327c: /bin/sh -c #(nop) MA
278
+01946d9d34d8: /bin/sh -c #(nop) MA
279
+c1d3b0166030: /bin/sh -c yum -y up
280
+41d50ecd2f57: /bin/sh -c #(nop) MA
281
+```
274 282
 
275 283
 To list all running containers with their labels in a table format you can use:
276 284
 
277
-    $ docker ps --format "table {{.ID}}\t{{.Labels}}"
278
-    CONTAINER ID        LABELS
279
-    a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
280
-    01946d9d34d8
281
-    c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
282
-    41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
285
+```bash
286
+$ docker ps --format "table {{.ID}}\t{{.Labels}}"
287
+
288
+CONTAINER ID        LABELS
289
+a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
290
+01946d9d34d8
291
+c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
292
+41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd
293
+```