@@ -29,15 +29,15 @@ By default, `docker inspect` will render results in a JSON array.
2929
3030If a format is specified, the given template will be executed for each result.
3131
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.
3434
3535## Specify target type (--type)
3636
3737` --type container|image|node|network|secret|service|volume|task|plugin `
3838
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)
4141exist with the same name, making the result ambiguous.
4242
4343To restrict ` docker inspect ` to a specific type of object, use the ` --type `
@@ -49,6 +49,35 @@ The following example inspects a _volume_ named "myvolume"
4949$ docker inspect --type=volume myvolume
5050```
5151
52+ ### <a name =size ></a > Inspect the size of a container (-s, --size)
53+
54+ The ` --size ` , or short-form ` -s ` , option adds two additional fields to the
55+ ` docker inspect ` output. This option only works for containers. The container
56+ doesn't have to be running, it also works for stopped containers.
57+
58+ ``` console
59+ $ docker inspect --size mycontainer
60+ ```
61+
62+ The output includes the full output of a regular ` docker inspect ` command, with
63+ the following additional fields:
64+
65+ - ` SizeRootFs ` : the total size of all the files in the container, in bytes.
66+ - ` SizeRw ` : the size of the files that have been created or changed in the
67+ container, compared to it's image, in bytes.
68+
69+ ``` console
70+ $ docker run --name database -d redis
71+ 3b2cbf074c99db4a0cad35966a9e24d7bc277f5565c17233386589029b7db273
72+ $ docker inspect --size database -f ' {{ .SizeRootFs }}'
73+ 123125760
74+ $ docker inspect --size database -f ' {{ .SizeRw }}'
75+ 8192
76+ $ docker exec database fallocate -l 1000 /newfile
77+ $ docker inspect --size database -f ' {{ .SizeRw }}'
78+ 12288
79+ ```
80+
5281## Examples
5382
5483### Get an instance's IP address
@@ -80,33 +109,30 @@ $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
80109
81110### List all port bindings
82111
83- You can loop over arrays and maps in the results to produce simple text
84- output:
112+ You can loop over arrays and maps in the results to produce simple text output:
85113
86114``` console
87115$ docker inspect --format=' {{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
88116```
89117
90118### Find a specific port mapping
91119
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.
120+ The ` .Field ` syntax doesn't work when the field name begins with a number, but
121+ the template language's ` index ` function does. The ` .NetworkSettings.Ports `
122+ section contains a map of the internal port mappings to a list of external
123+ address/port objects. To grab just the numeric public port, you use ` index ` to
124+ find the specific port map, and then ` index ` 0 contains the first object inside
125+ of that. Then we ask for the ` HostPort ` field to get the public address.
99126
100127``` console
101128$ docker inspect --format=' {{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
102129```
103130
104131### Get a subsection in JSON format
105132
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.
133+ If you request a field which is itself a structure containing other fields, by
134+ default you get a Go-style dump of the inner values. Docker adds a template
135+ function, ` json ` , which can be applied to get results in JSON format.
110136
111137``` console
112138$ docker inspect --format=' {{json .Config}}' $INSTANCE_ID
0 commit comments