docker inspect命令-显示更底层的容器或image信息

inspect 显示更底层的容器或image信息

Usage: docker inspect CONTAINER|IMAGE [CONTAINER|IMAGE...]Return low-level information on a container or image


-f,--format=""Format the output using the given go template.

默认返回一个json字符串,更具结构自行提取信息即可

Go's text/template package describes all the details of the format.

Examples

显示实例ip:

For the most part, you can pick out any field from the JSON in a fairly straightforward manner.

$ sudo docker inspect --format='{{.NetworkSettings.IPAddress}}' $INSTANCE_ID

列出所有绑定的端口:

One can loop over arrays and maps in the results to produce simple text output:

$ sudo docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID

找出特殊的端口映射:

The .Field syntax doesn't work when the field name begins with a number, but the template language'sindex function does. The .NetworkSettings.Ports section contains a map of the internal port mappings to a list of external address/port objects, so to grab just the numeric public port, you use indexto find the specific port map, and then index 0 contains first object inside of that. Then we ask for theHostPort field to get the public address.

$ sudo docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID

获取配置信息:

The .Field syntax doesn't work when the field contains JSON data, but the template language's customjson function does. The .config section contains complex json object, so to grab it as JSON, you usejson to convert config object into JSON

$ sudo docker inspect --format='{{json .config}}' $INSTANCE_ID