github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/cli/docs/reference/commandline/inspect.md (about) 1 --- 2 title: "inspect" 3 description: "The inspect command description and usage" 4 keywords: "inspect, container, json" 5 --- 6 7 # inspect 8 9 ```markdown 10 Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...] 11 12 Return low-level information on Docker object(s) (e.g. container, image, volume, 13 network, node, service, or task) identified by name or ID 14 15 Options: 16 -f, --format Format the output using the given Go template 17 --help Print usage 18 -s, --size Display total file sizes if the type is container 19 --type Return JSON for specified type 20 ``` 21 22 ## Description 23 24 Docker inspect provides detailed information on constructs controlled by Docker. 25 26 By default, `docker inspect` will render results in a JSON array. 27 28 ### <a name="format"></a> Format the output (--format) 29 30 If a format is specified, the given template will be executed for each result. 31 32 Go's [text/template](https://golang.org/pkg/text/template/) package describes 33 all the details of the format. 34 35 ### <a name="type"></a> Specify target type (--type) 36 37 `--type container|image|node|network|secret|service|volume|task|plugin` 38 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 exist with the same name, making the result ambiguous. 42 43 To restrict `docker inspect` to a specific type of object, use the `--type` 44 option. 45 46 The following example inspects a _volume_ named "myvolume" 47 48 ```console 49 $ docker inspect --type=volume myvolume 50 ``` 51 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 81 ## Examples 82 83 ### Get an instance's IP address 84 85 For the most part, you can pick out any field from the JSON in a fairly 86 straightforward manner. 87 88 ```console 89 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID 90 ``` 91 92 ### Get an instance's MAC address 93 94 ```console 95 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID 96 ``` 97 98 ### Get an instance's log path 99 100 ```console 101 $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID 102 ``` 103 104 ### Get an instance's image name 105 106 ```console 107 $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID 108 ``` 109 110 ### List all port bindings 111 112 You can loop over arrays and maps in the results to produce simple text output: 113 114 ```console 115 $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID 116 ``` 117 118 ### Find a specific port mapping 119 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. 126 127 ```console 128 $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID 129 ``` 130 131 ### Get a subsection in JSON format 132 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. 136 137 ```console 138 $ docker inspect --format='{{json .Config}}' $INSTANCE_ID 139 ```