mirror of https://github.com/docker/cli.git
docs: docker inspect: reformat with prettier
Signed-off-by: David Karlsson <david.karlsson@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 802c53fa9d
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
42eca75740
commit
226a2fd64e
|
@ -29,15 +29,15 @@ By default, `docker inspect` will render results in a JSON array.
|
||||||
|
|
||||||
If a format is specified, the given template will be executed for each result.
|
If a format is specified, the given template will be executed for each result.
|
||||||
|
|
||||||
Go's [text/template](https://golang.org/pkg/text/template/) package
|
Go's [text/template](https://golang.org/pkg/text/template/) package describes
|
||||||
describes all the details of the format.
|
all the details of the format.
|
||||||
|
|
||||||
## Specify target type (--type)
|
## Specify target type (--type)
|
||||||
|
|
||||||
`--type container|image|node|network|secret|service|volume|task|plugin`
|
`--type container|image|node|network|secret|service|volume|task|plugin`
|
||||||
|
|
||||||
The `docker inspect` command matches any type of object by either ID or name.
|
The `docker inspect` command matches any type of object by either ID or name. In
|
||||||
In some cases multiple type of objects (for example, a container and a volume)
|
some cases multiple type of objects (for example, a container and a volume)
|
||||||
exist with the same name, making the result ambiguous.
|
exist with the same name, making the result ambiguous.
|
||||||
|
|
||||||
To restrict `docker inspect` to a specific type of object, use the `--type`
|
To restrict `docker inspect` to a specific type of object, use the `--type`
|
||||||
|
@ -80,8 +80,7 @@ $ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
|
||||||
|
|
||||||
### List all port bindings
|
### List all port bindings
|
||||||
|
|
||||||
You can loop over arrays and maps in the results to produce simple text
|
You can loop over arrays and maps in the results to produce simple text output:
|
||||||
output:
|
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
|
||||||
|
@ -89,13 +88,12 @@ $ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}}
|
||||||
|
|
||||||
### Find a specific port mapping
|
### Find a specific port mapping
|
||||||
|
|
||||||
The `.Field` syntax doesn't work when the field name begins with a
|
The `.Field` syntax doesn't work when the field name begins with a number, but
|
||||||
number, but the template language's `index` function does. The
|
the template language's `index` function does. The `.NetworkSettings.Ports`
|
||||||
`.NetworkSettings.Ports` section contains a map of the internal port
|
section contains a map of the internal port mappings to a list of external
|
||||||
mappings to a list of external address/port objects. To grab just the
|
address/port objects. To grab just the numeric public port, you use `index` to
|
||||||
numeric public port, you use `index` to find the specific port map, and
|
find the specific port map, and then `index` 0 contains the first object inside
|
||||||
then `index` 0 contains the first object inside of that. Then we ask for
|
of that. Then we ask for the `HostPort` field to get the public address.
|
||||||
the `HostPort` field to get the public address.
|
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
|
||||||
|
@ -103,10 +101,9 @@ $ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0)
|
||||||
|
|
||||||
### Get a subsection in JSON format
|
### Get a subsection in JSON format
|
||||||
|
|
||||||
If you request a field which is itself a structure containing other
|
If you request a field which is itself a structure containing other fields, by
|
||||||
fields, by default you get a Go-style dump of the inner values.
|
default you get a Go-style dump of the inner values. Docker adds a template
|
||||||
Docker adds a template function, `json`, which can be applied to get
|
function, `json`, which can be applied to get results in JSON format.
|
||||||
results in JSON format.
|
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
|
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
|
||||||
|
|
Loading…
Reference in New Issue