2016-10-14 18:30:36 -04:00
|
|
|
---
|
|
|
|
title: "inspect"
|
|
|
|
description: "The inspect command description and usage"
|
2016-11-03 18:48:30 -04:00
|
|
|
keywords: "inspect, container, json"
|
2016-10-14 18:30:36 -04:00
|
|
|
---
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
# inspect
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
```markdown
|
2016-06-16 00:41:54 -04:00
|
|
|
Usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-09-18 01:11:02 -04:00
|
|
|
Return low-level information on Docker object(s) (e.g. container, image, volume,
|
|
|
|
network, node, service, or task) identified by name or ID
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-09-12 06:34:44 -04:00
|
|
|
Options:
|
2016-10-18 06:50:11 -04:00
|
|
|
-f, --format Format the output using the given Go template
|
2016-09-12 06:34:44 -04:00
|
|
|
--help Print usage
|
2016-07-07 14:43:18 -04:00
|
|
|
-s, --size Display total file sizes if the type is container
|
2016-09-12 06:34:44 -04:00
|
|
|
--type Return JSON for specified type
|
2016-07-07 14:43:18 -04:00
|
|
|
```
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
|
|
|
|
2017-03-10 12:08:41 -05:00
|
|
|
Docker inspect provides detailed information on constructs controlled by Docker.
|
|
|
|
|
|
|
|
By default, `docker inspect` will render results in a JSON array.
|
|
|
|
|
|
|
|
## Request a custom response format (--format)
|
|
|
|
|
2015-12-28 03:29:39 -05:00
|
|
|
If a format is specified, the given template will be executed for each result.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
Go's [text/template](http://golang.org/pkg/text/template/) package
|
|
|
|
describes all the details of the format.
|
|
|
|
|
2017-03-10 12:08:41 -05:00
|
|
|
## Specify target type (--type)
|
|
|
|
|
|
|
|
`--type container|image|node|network|secret|service|volume|task|plugin`
|
|
|
|
|
|
|
|
The `docker inspect` command matches any type of object by either ID or name.
|
|
|
|
In some cases multiple type of objects (for example, a container and a volume)
|
2017-10-31 06:21:09 -04:00
|
|
|
exist with the same name, making the result ambiguous.
|
2017-03-10 12:08:41 -05:00
|
|
|
|
|
|
|
To restrict `docker inspect` to a specific type of object, use the `--type`
|
|
|
|
option.
|
|
|
|
|
|
|
|
The following example inspects a _volume_ named "myvolume"
|
|
|
|
|
|
|
|
```bash
|
|
|
|
$ docker inspect --type=volume myvolume
|
|
|
|
```
|
|
|
|
|
2015-06-21 16:41:38 -04:00
|
|
|
## Examples
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Get an instance's IP address
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
For the most part, you can pick out any field from the JSON in a fairly
|
|
|
|
straightforward manner.
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Get an instance's MAC address
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Get an instance's log path
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Get an instance's image name
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
2017-03-16 16:48:04 -04:00
|
|
|
$ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
|
2017-02-07 18:42:48 -05:00
|
|
|
```
|
2016-06-13 22:57:19 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### List all port bindings
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
You can loop over arrays and maps in the results to produce simple text
|
2015-06-21 16:41:38 -04:00
|
|
|
output:
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Find a specific port mapping
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
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
|
2015-09-30 16:11:36 -04:00
|
|
|
mappings to a list of external address/port objects. To grab just the
|
2015-06-21 16:41:38 -04:00
|
|
|
numeric public port, you use `index` to find the specific port map, and
|
|
|
|
then `index` 0 contains the first object inside of that. Then we ask for
|
|
|
|
the `HostPort` field to get the public address.
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
|
|
|
```
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
### Get a subsection in JSON format
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2015-12-15 08:35:55 -05:00
|
|
|
If you request a field which is itself a structure containing other
|
|
|
|
fields, by default you get a Go-style dump of the inner values.
|
|
|
|
Docker adds a template function, `json`, which can be applied to get
|
|
|
|
results in JSON format.
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
```bash
|
|
|
|
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
|
|
|
|
```
|