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

Patricia Arquette
Release: 2024-11-11 21:47:02
Original
794 people have browsed it

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"
Copy after login

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

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

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

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

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template