参考Package template in Go programming.
基本规则:用.
号取map的值,用index
取数组的值。
index
的用法:index <array-name> <index-number>
range
的用法:{{range pipeline}} T1 {{end}}
表达式pipeline
返回值(必须是一个map或者array)的各个元素赋给T1
中的.
,
例如下面的例子中,{{.NetworkSettings.Networks}}
的返回值是一个key为bridge
的map对象,
它被赋给T1
(这里是{{.IPAddress}}
)中的.
,所以{{.IPAddress}}
的值是"172.31.254.3".
示例:
root@node1:~# docker inspect angry_wing
[
{
"Id": "e30f58ac1610c8607205d612b4389b361c5f6745e999bb5c8086f11f4b4e5903",
"Config": {
"Hostname": "e30f58ac1610",
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"DEBIAN_FRONTEND=noninteractive",
"DEBCONF_NONINTERACTIVE_SEEN=true"
],
"Entrypoint": [
"/entrypoint.sh"
]
},
"NetworkSettings": {
"Networks": {
"bridge": {
"IPAddress": "172.31.254.3"
}
}
}
}
]
root@node1:~# docker inspect --format='{{.NetworkSettings.Networks}}' angry_wing
map[bridge:0xc8200aa3c0]
root@node1:~# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' angry_wing
172.31.254.3
root@node1:~# docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' angry_wing
172.31.254.3
root@node1:~# docker inspect --format='{{.Config.Entrypoint}}' angry_wing
[/entrypoint.sh]
root@node1:~# docker inspect --format='{{range .Config.Entrypoint}}{{.}}{{end}}' angry_wing
/entrypoint.sh
root@node1:~# docker inspect --format='{{index .Config.Env 0}}' angry_wing
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@node1:~# docker inspect --format='{{range .Config.Env}}{{.}}; {{end}}' angry_wing
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin; DEBIAN_FRONTEND=noninteractive; DEBCONF_NONINTERACTIVE_SEEN=true;