Docker InspectEstimated reading Time:2 minutes
Description
Return low-level information on Docker objects Usage
Docker inspect [OPTIONS] name|id [name|id ...]
Options
Name, Shorthand |
Default |
Description |
--format, F |
|
Format the output using the given go template |
--size, S |
False |
Display Total File sizes If the type is container |
--type |
|
Return JSON for specified type |
Parent Command
Command |
Description |
Docker |
The base command for the Docker CLI. |
Extended Description
By default, Docker inspect'll render all results in a JSON array. If the container and image have the same name, this'll return container JSON for unspecified type. The If a format is specified, the given template would be executed for each result.
Go's Text/template package describes all the details of the format. examples Get a instance ' s IP address
For the most part, you can pick out any field from the JSON in a fairly straightforward manner.
$ docker Inspect--format= ' {{range. networksettings.networks}}{{. Ipaddress}}{{end} ' $INSTANCE _id
Get a instance ' s MAC address
$ docker Inspect--format= ' {{range. networksettings.networks}}{{. Macaddress}}{{end} ' $INSTANCE _id
Get an instance ' s log path
$ docker Inspect--format= ' {{. LogPath} ' $INSTANCE _id
Get an instance ' s image name
$ docker Inspect--format= ' {{. Config.image} ' $INSTANCE _id
List all Port bindings
can loop over arrays and maps in the results to produce simple text output:
$ docker Inspect--format= ' {{range $p, $conf: =. Networksettings.ports} {{$p}}}-> {{(index $conf 0). Hostport} {{end}} ' $INSTANCE _id
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. To grab just the "Numeric public port", use index to find the specific port map, and then index 0 contains the ECT inside of that. Then We for the "hostport field to get the" public address.
$ docker Inspect--format= ' {{(index. Networksettings.ports "8787/tcp") 0). Hostport} ' $INSTANCE _id
Get a subsection in JSON format
If you request a field which are itself a structure containing other fields, by default and get a go-style dump of the Inne R values. Docker adds a template function, JSON, which can is applied to get results in JSON format.
$ docker Inspect--format= ' {{json. Config}} ' $INSTANCE _id