From 802c53fa9d73f4f5a6156131219a16def33757dd Mon Sep 17 00:00:00 2001 From: David Karlsson Date: Fri, 28 Oct 2022 10:57:23 +0200 Subject: [PATCH 1/2] docs: docker inspect: reformat with prettier Signed-off-by: David Karlsson Signed-off-by: Sebastiaan van Stijn --- docs/reference/commandline/inspect.md | 31 ++++++++++++--------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/docs/reference/commandline/inspect.md b/docs/reference/commandline/inspect.md index 36b2d202e1..2b7ab9fd53 100644 --- a/docs/reference/commandline/inspect.md +++ b/docs/reference/commandline/inspect.md @@ -29,15 +29,15 @@ By default, `docker inspect` will render results in a JSON array. If a format is specified, the given template will be executed for each result. -Go's [text/template](https://golang.org/pkg/text/template/) package -describes all the details of the format. +Go's [text/template](https://golang.org/pkg/text/template/) package describes +all the details of the format. ### Specify target type (--type) `--type container|image|node|network|secret|service|volume|task|plugin` -The `docker inspect` command matches any type of object by either ID or name. -In some cases multiple type of objects (for example, a container and a volume) +The `docker inspect` command matches any type of object by either ID or name. In +some cases multiple type of objects (for example, a container and a volume) exist with the same name, making the result ambiguous. To restrict `docker inspect` to a specific type of object, use the `--type` @@ -80,8 +80,7 @@ $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID ### List all port bindings -You can loop over arrays and maps in the results to produce simple text -output: +You can loop over arrays and maps in the results to produce simple text output: ```console $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID @@ -89,13 +88,12 @@ $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} ### Find a specific port mapping -The `.Field` syntax doesn't work when the field name begins with a -number, but the template language's `index` function does. The -`.NetworkSettings.Ports` section contains a map of the internal port -mappings to a list of external address/port objects. To grab just the -numeric public port, you use `index` to find the specific port map, and -then `index` 0 contains the first object inside of that. Then we ask for -the `HostPort` field to get the public address. +The `.Field` syntax doesn't work when the field name begins with a number, but +the template language's `index` function does. The `.NetworkSettings.Ports` +section contains a map of the internal port mappings to a list of external +address/port objects. To grab just the numeric public port, you use `index` to +find the specific port map, and then `index` 0 contains the first object inside +of that. Then we ask for the `HostPort` field to get the public address. ```console $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID @@ -103,10 +101,9 @@ $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0) ### Get a subsection in JSON format -If you request a field which is itself a structure containing other -fields, by default you get a Go-style dump of the inner values. -Docker adds a template function, `json`, which can be applied to get -results in JSON format. +If you request a field which is itself a structure containing other fields, by +default you get a Go-style dump of the inner values. Docker adds a template +function, `json`, which can be applied to get results in JSON format. ```console $ docker inspect --format='{{json .Config}}' $INSTANCE_ID From e064f893a6ea2772f7db03a4a41808fa859959cf Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 17 Nov 2022 14:17:23 +0100 Subject: [PATCH 2/2] docs: docker inspect --size Signed-off-by: David Karlsson Signed-off-by: Sebastiaan van Stijn --- docs/reference/commandline/inspect.md | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/reference/commandline/inspect.md b/docs/reference/commandline/inspect.md index 2b7ab9fd53..6419d7b4fa 100644 --- a/docs/reference/commandline/inspect.md +++ b/docs/reference/commandline/inspect.md @@ -49,6 +49,35 @@ The following example inspects a _volume_ named "myvolume" $ docker inspect --type=volume myvolume ``` +### Inspect the size of a container (-s, --size) + +The `--size`, or short-form `-s`, option adds two additional fields to the +`docker inspect` output. This option only works for containers. The container +doesn't have to be running, it also works for stopped containers. + +```console +$ docker inspect --size mycontainer +``` + +The output includes the full output of a regular `docker inspect` command, with +the following additional fields: + +- `SizeRootFs`: the total size of all the files in the container, in bytes. +- `SizeRw`: the size of the files that have been created or changed in the + container, compared to it's image, in bytes. + +```console +$ docker run --name database -d redis +3b2cbf074c99db4a0cad35966a9e24d7bc277f5565c17233386589029b7db273 +$ docker inspect --size database -f '{{ .SizeRootFs }}' +123125760 +$ docker inspect --size database -f '{{ .SizeRw }}' +8192 +$ docker exec database fallocate -l 1000 /newfile +$ docker inspect --size database -f '{{ .SizeRw }}' +12288 +``` + ## Examples ### Get an instance's IP address