github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/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 <!-- This file is maintained within the docker/cli GitHub 8 repository at https://github.com/docker/cli/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # inspect 17 18 ```markdown 19 Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...] 20 21 Return low-level information on Docker object(s) (e.g. container, image, volume, 22 network, node, service, or task) identified by name or ID 23 24 Options: 25 -f, --format Format the output using the given Go template 26 --help Print usage 27 -s, --size Display total file sizes if the type is container 28 --type Return JSON for specified type 29 ``` 30 31 ## Description 32 33 Docker inspect provides detailed information on constructs controlled by Docker. 34 35 By default, `docker inspect` will render results in a JSON array. 36 37 ## Request a custom response format (--format) 38 39 If a format is specified, the given template will be executed for each result. 40 41 Go's [text/template](http://golang.org/pkg/text/template/) package 42 describes all the details of the format. 43 44 ## Specify target type (--type) 45 46 `--type container|image|node|network|secret|service|volume|task|plugin` 47 48 The `docker inspect` command matches any type of object by either ID or name. 49 In some cases multiple type of objects (for example, a container and a volume) 50 exist with the same name, making the result ambiguous. 51 52 To restrict `docker inspect` to a specific type of object, use the `--type` 53 option. 54 55 The following example inspects a _volume_ named "myvolume" 56 57 ```bash 58 $ docker inspect --type=volume myvolume 59 ``` 60 61 ## Examples 62 63 ### Get an instance's IP address 64 65 For the most part, you can pick out any field from the JSON in a fairly 66 straightforward manner. 67 68 ```bash 69 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID 70 ``` 71 72 ### Get an instance's MAC address 73 74 ```bash 75 $ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID 76 ``` 77 78 ### Get an instance's log path 79 80 ```bash 81 $ docker inspect --format='{{.LogPath}}' $INSTANCE_ID 82 ``` 83 84 ### Get an instance's image name 85 86 ```bash 87 $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID 88 ``` 89 90 ### List all port bindings 91 92 You can loop over arrays and maps in the results to produce simple text 93 output: 94 95 ```bash 96 $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID 97 ``` 98 99 ### Find a specific port mapping 100 101 The `.Field` syntax doesn't work when the field name begins with a 102 number, but the template language's `index` function does. The 103 `.NetworkSettings.Ports` section contains a map of the internal port 104 mappings to a list of external address/port objects. To grab just the 105 numeric public port, you use `index` to find the specific port map, and 106 then `index` 0 contains the first object inside of that. Then we ask for 107 the `HostPort` field to get the public address. 108 109 ```bash 110 $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID 111 ``` 112 113 ### Get a subsection in JSON format 114 115 If you request a field which is itself a structure containing other 116 fields, by default you get a Go-style dump of the inner values. 117 Docker adds a template function, `json`, which can be applied to get 118 results in JSON format. 119 120 ```bash 121 $ docker inspect --format='{{json .Config}}' $INSTANCE_ID 122 ```