github.com/brahmaroutu/docker@v1.2.1-0.20160809185609-eb28dde01f16/docs/reference/commandline/inspect.md (about) 1 <!--[metadata]> 2 +++ 3 title = "inspect" 4 description = "The inspect command description and usage" 5 keywords = ["inspect, container, json"] 6 [menu.main] 7 parent = "smn_cli" 8 +++ 9 <![end-metadata]--> 10 11 # inspect 12 13 ```markdown 14 Usage: docker inspect [OPTIONS] CONTAINER|IMAGE|TASK [CONTAINER|IMAGE|TASK...] 15 16 Return low-level information on a container, image or task 17 18 -f, --format Format the output using the given go template 19 --help Print usage 20 -s, --size Display total file sizes if the type is container 21 values are "image" or "container" or "task 22 --type Return JSON for specified type, (e.g image, container or task) 23 ``` 24 25 By default, this will render all results in a JSON array. If the container and 26 image have the same name, this will return container JSON for unspecified type. 27 If a format is specified, the given template will be executed for each result. 28 29 Go's [text/template](http://golang.org/pkg/text/template/) package 30 describes all the details of the format. 31 32 ## Examples 33 34 **Get an instance's IP address:** 35 36 For the most part, you can pick out any field from the JSON in a fairly 37 straightforward manner. 38 39 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID 40 41 **Get an instance's MAC address:** 42 43 For the most part, you can pick out any field from the JSON in a fairly 44 straightforward manner. 45 46 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID 47 48 **Get an instance's log path:** 49 50 $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID 51 52 **Get a Task's image name:** 53 54 $ docker inspect --format='{{.Container.Spec.Image}}' $INSTANCE_ID 55 56 **List all port bindings:** 57 58 One can loop over arrays and maps in the results to produce simple text 59 output: 60 61 $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID 62 63 **Find a specific port mapping:** 64 65 The `.Field` syntax doesn't work when the field name begins with a 66 number, but the template language's `index` function does. The 67 `.NetworkSettings.Ports` section contains a map of the internal port 68 mappings to a list of external address/port objects. To grab just the 69 numeric public port, you use `index` to find the specific port map, and 70 then `index` 0 contains the first object inside of that. Then we ask for 71 the `HostPort` field to get the public address. 72 73 $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID 74 75 **Get a subsection in JSON format:** 76 77 If you request a field which is itself a structure containing other 78 fields, by default you get a Go-style dump of the inner values. 79 Docker adds a template function, `json`, which can be applied to get 80 results in JSON format. 81 82 $ docker inspect --format='{{json .Config}}' $INSTANCE_ID