Home  >  Article  >  Backend Development  >  How to Extract Docker Image Labels with Dotted Names Using `docker inspect`?

How to Extract Docker Image Labels with Dotted Names Using `docker inspect`?

Patricia Arquette
Patricia ArquetteOriginal
2024-11-11 21:47:02802browse

How to Extract Docker Image Labels with Dotted Names Using `docker inspect`?

Extracting Docker Image Labels with Dotted Names

When encountering Docker images that have labels with dotted names, the standard docker inspect command using the --format option can fail. This can present challenges when attempting to retrieve such labels from within scripts.

The Absence of Dotted Names in Label Lookup

Consider the following Docker image with labeled names:

FROM busybox
LABEL foo="bar"
LABEL com.wherever.foo="bang"

Using the --format option, retrieving the value of the foo label is straightforward:

$ docker inspect -f '{{ .Config.Labels.foo }}' foo
bar

However, accessing the com.wherever.foo label fails:

$ docker inspect -f '{{ .Config.Labels.com.wherever.foo }}' foo
<no value>

Solution: Utilizing the Index Function

To resolve this issue, one can utilize the index function, capable of retrieving arbitrary string keys from a map. By incorporating it into the --format option, the dotted label can be successfully extracted:

$ docker inspect -f '{{ index .Config.Labels "com.wherever.foo" }}' foo
bang

The above is the detailed content of How to Extract Docker Image Labels with Dotted Names Using `docker inspect`?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn