从docker中获取标签值

前端之家收集整理的这篇文章主要介绍了从docker中获取标签值前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参见英文答案 > How can I get a Docker image’s label if the label name has a “.” in it?                                    1个
由于密钥具有“.”,因此我无法从地图列表中获取值.内.

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]

但是如何从密钥com.docker.compose.project获取项目名称new

docker inspect -f {{.Config.Labels.com.docker.compose.project}} new_sc2_1
最佳答案
您可以使用index来获取该键的值(为了便于阅读而包装);

docker inspect \
  --format "{{ index .Config.Labels \"com.docker.compose.project\"}}" \
  new_sc2_1

这应该给你项目的名称

猜你在找的Docker相关文章