2015-06-21 16:41:38 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "inspect"
|
|
|
|
description = "The inspect command description and usage"
|
|
|
|
keywords = ["inspect, container, json"]
|
|
|
|
[menu.main]
|
|
|
|
parent = "smn_cli"
|
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
|
|
|
|
|
|
|
# inspect
|
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
```markdown
|
|
|
|
Usage: docker inspect [OPTIONS] CONTAINER|IMAGE|TASK [CONTAINER|IMAGE|TASK...]
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
Return low-level information on a container, image or task
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-07-07 14:43:18 -04:00
|
|
|
-f, --format Format the output using the given go template
|
|
|
|
--help Print usage
|
|
|
|
-s, --size Display total file sizes if the type is container
|
|
|
|
values are "image" or "container" or "task
|
|
|
|
--type Return JSON for specified type, (e.g image, container or task)
|
|
|
|
```
|
2015-06-26 10:47:31 -04:00
|
|
|
|
2015-12-28 03:29:39 -05:00
|
|
|
By default, this will render all results in a JSON array. If the container and
|
|
|
|
image have the same name, this will return container JSON for unspecified type.
|
|
|
|
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.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
**Get an instance's IP address:**
|
|
|
|
|
|
|
|
For the most part, you can pick out any field from the JSON in a fairly
|
|
|
|
straightforward manner.
|
|
|
|
|
2015-09-30 16:11:36 -04:00
|
|
|
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
|
2015-06-21 16:41:38 -04:00
|
|
|
|
2016-06-13 00:30:14 -04:00
|
|
|
**Get an instance's MAC 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.
|
|
|
|
|
2016-01-22 02:23:22 -05:00
|
|
|
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
**Get an instance's log path:**
|
|
|
|
|
|
|
|
$ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
|
|
|
|
|
2016-06-13 22:57:19 -04:00
|
|
|
**Get a Task's image name:**
|
|
|
|
|
|
|
|
$ docker inspect --format='{{.Container.Spec.Image}}' $INSTANCE_ID
|
|
|
|
|
2016-06-13 00:30:14 -04:00
|
|
|
**List all port bindings:**
|
2015-06-21 16:41:38 -04:00
|
|
|
|
|
|
|
One 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
|
|
|
|
|
2016-06-13 00:30:14 -04: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.
|
|
|
|
|
|
|
|
$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
|
|
|
|
2015-12-15 08:35:55 -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
|
|
|
|
2015-12-15 08:35:55 -05:00
|
|
|
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
|