docker inspect命令-显示更底层的容器或image信息
inspect 显示更底层的容器或image信息
默认返回一个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.
列出所有绑定的端口:
One can loop over arrays and maps in the results to produce simple text output:
找出特殊的端口映射:
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 index
to 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.
获取配置信息:
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