-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Expand file tree
/
Copy pathdocker_inspect.yaml
More file actions
176 lines (142 loc) · 5.64 KB
/
docker_inspect.yaml
File metadata and controls
176 lines (142 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
command: docker inspect
short: Return low-level information on Docker objects
long: |-
Docker inspect provides detailed information on constructs controlled by Docker.
By default, `docker inspect` will render results in a JSON array.
usage: docker inspect [OPTIONS] NAME|ID [NAME|ID...]
pname: docker
plink: docker.yaml
options:
- option: format
shorthand: f
value_type: string
description: |-
Format output using a custom template:
'json': Print in JSON format
'TEMPLATE': Print output using the given Go template.
Refer to https://docs.docker.com/go/formatting/ for more information about formatting output with templates
details_url: '#format'
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: size
shorthand: s
value_type: bool
default_value: "false"
description: Display total file sizes if the type is container
details_url: '#size'
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
- option: type
value_type: string
description: Only inspect objects of the given type
details_url: '#type'
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
inherited_options:
- option: help
value_type: bool
default_value: "false"
description: Print usage
deprecated: false
hidden: true
experimental: false
experimentalcli: false
kubernetes: false
swarm: false
examples: |-
### Format the output (--format) {#format}
If a format is specified, the given template will be executed for each result.
Go's [text/template](https://pkg.go.dev/text/template) package describes
all the details of the format.
### Specify target type (--type) {#type}
`--type config|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)
exist with the same name, making the result ambiguous.
To restrict `docker inspect` to a specific type of object, use the `--type`
option.
The following example inspects a volume named `myvolume`.
```console
$ docker inspect --type=volume myvolume
```
### Inspect the size of a container (-s, --size) {#size}
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
$ docker inspect --size database -f '{{ .SizeRw }}'
8192
$ docker exec database fallocate -l 1000 /newfile
$ docker inspect --size database -f '{{ .SizeRw }}'
12288
```
### Get an instance's IP address
For the most part, you can pick out any field from the JSON in a fairly
straightforward manner.
```console
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
```
### Get an instance's MAC address
```console
$ docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $INSTANCE_ID
```
### Get an instance's log path
```console
$ docker inspect --format='{{.LogPath}}' $INSTANCE_ID
```
### Get an instance's image name
```console
$ docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
```
### List all port bindings
You can loop over arrays and maps in the results to produce simple text output:
```console
$ docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{with $conf}}{{(index . 0).HostPort}}{{else}}none{{end}} {{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 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
of that. Then, specify the `HostPort` field to get the public address.
```console
$ docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
```
### Get a subsection in JSON format
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.
```console
$ docker inspect --format='{{json .Config}}' $INSTANCE_ID
```
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
swarm: false