...
1# inspect
2
3<!---MARKER_GEN_START-->
4Return low-level information on Docker objects
5
6### Options
7
8| Name | Type | Default | Description |
9|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
10| [`-f`](#format), [`--format`](#format) | `string` | | Format output using a custom template:<br>'json': Print in JSON format<br>'TEMPLATE': Print output using the given Go template.<br>Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
11| [`-s`](#size), [`--size`](#size) | | | Display total file sizes if the type is container |
12| [`--type`](#type) | `string` | | Return JSON for specified type |
13
14
15<!---MARKER_GEN_END-->
16
17## Description
18
19Docker inspect provides detailed information on constructs controlled by Docker.
20
21By default, `docker inspect` will render results in a JSON array.
22
23### <a name="format"></a> Format the output (--format)
24
25If a format is specified, the given template will be executed for each result.
26
27Go's [text/template](https://pkg.go.dev/text/template) package describes
28all the details of the format.
29
30### <a name="type"></a> Specify target type (--type)
31
32`--type container|image|node|network|secret|service|volume|task|plugin`
33
34The `docker inspect` command matches any type of object by either ID or name. In
35some cases multiple type of objects (for example, a container and a volume)
36exist with the same name, making the result ambiguous.
37
38To restrict `docker inspect` to a specific type of object, use the `--type`
39option.
40
41The following example inspects a volume named `myvolume`.
42
43```console
44$ docker inspect --type=volume myvolume
45```
46
47### <a name="size"></a> Inspect the size of a container (-s, --size)
48
49The `--size`, or short-form `-s`, option adds two additional fields to the
50`docker inspect` output. This option only works for containers. The container
51doesn't have to be running, it also works for stopped containers.
52
53```console
54$ docker inspect --size mycontainer
55```
56
57The output includes the full output of a regular `docker inspect` command, with
58the following additional fields:
59
60- `SizeRootFs`: the total size of all the files in the container, in bytes.
61- `SizeRw`: the size of the files that have been created or changed in the
62 container, compared to it's image, in bytes.
63
64```console
65$ docker run --name database -d redis
663b2cbf074c99db4a0cad35966a9e24d7bc277f5565c17233386589029b7db273
67$ docker inspect --size database -f '{{ .SizeRootFs }}'
68123125760
69$ docker inspect --size database -f '{{ .SizeRw }}'
708192
71$ docker exec database fallocate -l 1000 /newfile
72$ docker inspect --size database -f '{{ .SizeRw }}'
7312288
74```
75
76## Examples
77
78### Get an instance's IP address
79
80For the most part, you can pick out any field from the JSON in a fairly
81straightforward manner.
82
83```console
84$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
85```
86
87### Get an instance's MAC address
88
89```console
90$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
91```
92
93### Get an instance's log path
94
95```console
96$ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
97```
98
99### Get an instance's image name
100
101```console
102$ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
103```
104
105### List all port bindings
106
107You can loop over arrays and maps in the results to produce simple text output:
108
109```console
110$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
111```
112
113### Find a specific port mapping
114
115The `.Field` syntax doesn't work when the field name begins with a number, but
116the template language's `index` function does. The `.NetworkSettings.Ports`
117section contains a map of the internal port mappings to a list of external
118address/port objects. To grab just the numeric public port, you use `index` to
119find the specific port map, and then `index` 0 contains the first object inside
120of that. Then, specify the `HostPort` field to get the public address.
121
122```console
123$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
124```
125
126### Get a subsection in JSON format
127
128If you request a field which is itself a structure containing other fields, by
129default you get a Go-style dump of the inner values. Docker adds a template
130function, `json`, which can be applied to get results in JSON format.
131
132```console
133$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
134```
View as plain text