2015-06-21 16:41:38 -04:00
# inspect
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_START -->
Return low-level information on Docker objects
### Options
| Name | Type | Default | Description |
|:---------------------------------------|:---------|:--------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`-f` ](#format ), [`--format` ](#format ) | `string` | | Format output using a custom template:< br > 'json': Print in JSON format< br > 'TEMPLATE': Print output using the given Go template.< br > Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates |
2024-07-03 02:29:57 -04:00
| [`-s` ](#size ), [`--size` ](#size ) | `bool` | | Display total file sizes if the type is container |
2023-01-06 13:04:05 -05:00
| [`--type` ](#type ) | `string` | | Return JSON for specified type |
2015-06-21 16:41:38 -04:00
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_END -->
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.
2023-01-06 13:28:29 -05:00
### <a name="format"></a> Format the output (--format)
2017-03-10 12:08:41 -05:00
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
2023-08-25 08:10:40 -04:00
Go's [text/template ](https://pkg.go.dev/text/template ) package describes
2022-10-28 04:57:23 -04:00
all the details of the format.
2015-06-21 16:41:38 -04:00
2023-01-06 13:28:29 -05:00
### <a name="type"></a> Specify target type (--type)
2017-03-10 12:08:41 -05:00
2024-10-24 12:28:35 -04:00
`--type config|container|image|node|network|secret|service|volume|task|plugin`
2017-03-10 12:08:41 -05:00
2022-10-28 04:57:23 -04:00
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.
2023-12-13 18:06:16 -05:00
The following example inspects a volume named `myvolume` .
2017-03-10 12:08:41 -05:00
2021-08-21 08:54:14 -04:00
```console
2017-03-10 12:08:41 -05:00
$ docker inspect --type=volume myvolume
```
2023-01-06 13:28:29 -05:00
### <a name="size"></a> Inspect the size of a container (-s, --size)
2022-11-17 08:17:23 -05:00
The `--size` , or short-form `-s` , option adds two additional fields to the
`docker inspect` output. This option only works for containers. The container
doesn't have to be running, it also works for stopped containers.
```console
$ docker inspect --size mycontainer
```
The output includes the full output of a regular `docker inspect` command, with
the following additional fields:
- `SizeRootFs` : the total size of all the files in the container, in bytes.
- `SizeRw` : the size of the files that have been created or changed in the
container, compared to it's image, in bytes.
```console
$ docker run --name database -d redis
3b2cbf074c99db4a0cad35966a9e24d7bc277f5565c17233386589029b7db273
$ docker inspect --size database -f '{{ .SizeRootFs }}'
123125760
2023-01-07 06:24:14 -05:00
$ docker inspect --size database -f '{{ .SizeRw }}'
2022-11-17 08:17:23 -05:00
8192
2023-01-07 06:24:14 -05:00
$ docker exec database fallocate -l 1000 /newfile
2022-11-17 08:17:23 -05:00
$ docker inspect --size database -f '{{ .SizeRw }}'
12288
```
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.
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ 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
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ 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
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ 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
2021-08-21 08:54:14 -04:00
```console
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
2022-10-28 04:57:23 -04:00
You can loop over arrays and maps in the results to produce simple text output:
2015-06-21 16:41:38 -04:00
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ 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
2022-10-28 04:57:23 -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 mappings to a list of external
address/port objects. To grab just the numeric public port, you use `index` to
find the specific port map, and then `index` 0 contains the first object inside
2023-12-13 18:06:16 -05:00
of that. Then, specify the `HostPort` field to get the public address.
2015-06-21 16:41:38 -04:00
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ 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
2022-10-28 04:57:23 -04: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
2021-08-21 08:54:14 -04:00
```console
2017-02-07 18:42:48 -05:00
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
```