我有问题从地图列表中获取值,因为密钥有"。"内部。
docker inspect jenkins ... Config: { .. "Labels": { "com.docker.compose.config-hash": "85bcf1e0bcd708120185a303e2a8d8e65543c1ec77ec0c6762fc057dc10320aa", "com.docker.compose.container-number": "1", "com.docker.compose.oneoff": "False", "com.docker.compose.project": "new", "com.docker.compose.service": "sc2", "com.docker.compose.version": "1.5.2" } } }
我可以获得地图列表
docker inspect -f {{.Config.Labels}} new_sc2_1 map[com.docker.compose.config-hash:85bcf1e0bcd708120185a303e2a8d8e65543c1ec77ec0c6762fc057dc10320aa com.docker.compose.container-number:1 com.docker.compose.oneoff:False com.docker.compose.project:new com.docker.compose.service:sc2 com.docker.compose.version:1.5.2]
但是如何从密钥.htaccess
new
com.docker.compose.project
答案 0 :(得分:25)
您可以使用index
获取该密钥的值(为便于阅读而包装);
docker inspect \
--format '{{ index .Config.Labels "com.docker.compose.project"}}' \
new_sc2_1
那应该给你项目的名称
答案 1 :(得分:6)
您可以将git merge
的输出传输到docker inspect
。给出这样的内容:
jq
我可以像这样提取单个标签值:
...
"Labels": {
"com.docker.compose.config-hash": "a804d541a5828f4aaf17df862b650e58ac5bae77b70ff5ebdb2f0f3682326954",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "postgis",
"com.docker.compose.service": "postgis",
"com.docker.compose.version": "1.7.0rc1"
}
...
哪个让我:
docker inspect mycontainer |
jq -r '.[0].Config.Labels["com.docker.compose.project"]'