如果标签名称具有“。”,我如何获得Docker图像的标签。在里面? [英] How can I get a Docker image's label if the label name has a "." in it?
本文介绍了如果标签名称具有“。”,我如何获得Docker图像的标签。在里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
# - * - Dockerfile - * -
FROM busybox
LABEL foo =bar
LABEL com.wherever.foo =bang
对于简单的标签名称,inspect命令有一个非常有效的格式
选项(使用Go模板)。 p>
$ docker build -t foo。
$ docker inspect -f'{{.Config.Labels.foo}}'foo
bar
但是如何访问名称中有点的标签?
$ docker inspect -f' {{.Config.Labels.com.wherever.foo}}'foo
< no value>
我在一个bash脚本中写这个,我想避免重新解析
解决方案
<$ code> docker inspect的JSON输出 c $ c> index 函数是我正在寻找的。它可以查找地图中的任意字符串。
$ docker inspect -f'{{index .Config.Labelscom.wherever .foo}}'foo
bang
The docker inspect command can be very useful for getting the labels on a Docker image:
# -*- Dockerfile -*-
FROM busybox
LABEL foo="bar"
LABEL com.wherever.foo="bang"
For simple label names, the inspect command has a --format
option (which uses Go templates) that works nicely.
$ docker build -t foo .
$ docker inspect -f '{{ .Config.Labels.foo }}' foo
bar
But how do I access labels that have a dot in their name?
$ docker inspect -f '{{ .Config.Labels.com.wherever.foo }}' foo
<no value>
I'm writing this in a bash script, where I'd like to avoid re-parsing the JSON output from docker inspect
, if possible.
解决方案
The index
function is what I was looking for. It can lookup arbitrary strings in the map.
$ docker inspect -f '{{ index .Config.Labels "com.wherever.foo" }}' foo
bang
这篇关于如果标签名称具有“。”,我如何获得Docker图像的标签。在里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文