github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/inspect.md (about) 1 # inspect 2 3 <!---MARKER_GEN_START--> 4 Return 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 19 Docker inspect provides detailed information on constructs controlled by Docker. 20 21 By default, `docker inspect` will render results in a JSON array. 22 23 ### <a name="format"></a> Format the output (--format) 24 25 If a format is specified, the given template will be executed for each result. 26 27 Go's [text/template](https://pkg.go.dev/text/template) package describes 28 all 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 34 The `docker inspect` command matches any type of object by either ID or name. In 35 some cases multiple type of objects (for example, a container and a volume) 36 exist with the same name, making the result ambiguous. 37 38 To restrict `docker inspect` to a specific type of object, use the `--type` 39 option. 40 41 The 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 49 The `--size`, or short-form `-s`, option adds two additional fields to the 50 `docker inspect` output. This option only works for containers. The container 51 doesn't have to be running, it also works for stopped containers. 52 53 ```console 54 $ docker inspect --size mycontainer 55 ``` 56 57 The output includes the full output of a regular `docker inspect` command, with 58 the 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 66 3b2cbf074c99db4a0cad35966a9e24d7bc277f5565c17233386589029b7db273 67 $ docker inspect --size database -f '{{ .SizeRootFs }}' 68 123125760 69 $ docker inspect --size database -f '{{ .SizeRw }}' 70 8192 71 $ docker exec database fallocate -l 1000 /newfile 72 $ docker inspect --size database -f '{{ .SizeRw }}' 73 12288 74 ``` 75 76 ## Examples 77 78 ### Get an instance's IP address 79 80 For the most part, you can pick out any field from the JSON in a fairly 81 straightforward 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 107 You 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 115 The `.Field` syntax doesn't work when the field name begins with a number, but 116 the template language's `index` function does. The `.NetworkSettings.Ports` 117 section contains a map of the internal port mappings to a list of external 118 address/port objects. To grab just the numeric public port, you use `index` to 119 find the specific port map, and then `index` 0 contains the first object inside 120 of 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 128 If you request a field which is itself a structure containing other fields, by 129 default you get a Go-style dump of the inner values. Docker adds a template 130 function, `json`, which can be applied to get results in JSON format. 131 132 ```console 133 $ docker inspect --format='{{json .Config}}' $INSTANCE_ID 134 ```