首頁 > 後端開發 > Golang > 主體

如何使用「inspect」指令存取名稱中帶點的 Docker 映像標籤?

Patricia Arquette
發布: 2024-11-14 17:39:02
原創
248 人瀏覽過

How to Access Docker Image Labels with Dots in Their Names Using the `inspect` Command?

Accessing Docker Image Labels with Dots in Names

Docker's inspect command provides a convenient way to retrieve a container image's labels. However, extracting labels with dots in their names using the --format option and Go templates can prove challenging.

Issue:

The following Docker image defines two labels:

FROM busybox
LABEL foo="bar"
LABEL com.wherever.foo="bang"
登入後複製

Using the inspect command with the --format option:

$ docker inspect -f '{{ .Config.Labels.foo }}' foo
登入後複製

returns the value for the "foo" label correctly. However, trying to access the label with a dot in its name:

$ docker inspect -f '{{ .Config.Labels.com.wherever.foo }}' foo
登入後複製

results in "".

Solution:

To retrieve labels with dots in their names, use the index function within the Go template:

$ docker inspect -f '{{ index .Config.Labels "com.wherever.foo" }}' foo
登入後複製

This will output the desired label value, "bang".

The index function looks up arbitrary strings in the map and returns the corresponding value if found. By specifying the label name as the second parameter, the function retrieves the associated value from the Labels map of the Config object.

以上是如何使用「inspect」指令存取名稱中帶點的 Docker 映像標籤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板