@@ -29,15 +29,15 @@ By default, `docker inspect` will render results in a JSON array.
29
29
30
30
If a format is specified, the given template will be executed for each result.
31
31
32
- Go's [ text/template] ( https://golang.org/pkg/text/template/ ) package
33
- describes all the details of the format.
32
+ Go's [ text/template] ( https://golang.org/pkg/text/template/ ) package describes
33
+ all the details of the format.
34
34
35
35
## Specify target type (--type)
36
36
37
37
` --type container|image|node|network|secret|service|volume|task|plugin `
38
38
39
- The ` docker inspect ` command matches any type of object by either ID or name.
40
- In some cases multiple type of objects (for example, a container and a volume)
39
+ The ` docker inspect ` command matches any type of object by either ID or name. In
40
+ some cases multiple type of objects (for example, a container and a volume)
41
41
exist with the same name, making the result ambiguous.
42
42
43
43
To restrict ` docker inspect ` to a specific type of object, use the ` --type `
@@ -80,33 +80,30 @@ $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
80
80
81
81
### List all port bindings
82
82
83
- You can loop over arrays and maps in the results to produce simple text
84
- output:
83
+ You can loop over arrays and maps in the results to produce simple text output:
85
84
86
85
``` console
87
86
$ docker inspect --format=' {{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
88
87
```
89
88
90
89
### Find a specific port mapping
91
90
92
- The ` .Field ` syntax doesn't work when the field name begins with a
93
- number, but the template language's ` index ` function does. The
94
- ` .NetworkSettings.Ports ` section contains a map of the internal port
95
- mappings to a list of external address/port objects. To grab just the
96
- numeric public port, you use ` index ` to find the specific port map, and
97
- then ` index ` 0 contains the first object inside of that. Then we ask for
98
- the ` HostPort ` field to get the public address.
91
+ The ` .Field ` syntax doesn't work when the field name begins with a number, but
92
+ the template language's ` index ` function does. The ` .NetworkSettings.Ports `
93
+ section contains a map of the internal port mappings to a list of external
94
+ address/port objects. To grab just the numeric public port, you use ` index ` to
95
+ find the specific port map, and then ` index ` 0 contains the first object inside
96
+ of that. Then we ask for the ` HostPort ` field to get the public address.
99
97
100
98
``` console
101
99
$ docker inspect --format=' {{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
102
100
```
103
101
104
102
### Get a subsection in JSON format
105
103
106
- If you request a field which is itself a structure containing other
107
- fields, by default you get a Go-style dump of the inner values.
108
- Docker adds a template function, ` json ` , which can be applied to get
109
- results in JSON format.
104
+ If you request a field which is itself a structure containing other fields, by
105
+ default you get a Go-style dump of the inner values. Docker adds a template
106
+ function, ` json ` , which can be applied to get results in JSON format.
110
107
111
108
``` console
112
109
$ docker inspect --format=' {{json .Config}}' $INSTANCE_ID
0 commit comments