Home  >  Article  >  Backend Development  >  How to Access Docker Image Labels with Periods in Their Names?

How to Access Docker Image Labels with Periods in Their Names?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-09 00:38:02583browse

How to Access Docker Image Labels with Periods in Their Names?

Accessing Docker Image Labels with Periods in Names

Docker's docker inspect command provides a means to retrieve labels associated with Docker images. However, accessing labels with periods (".") in their names using the --format option poses a challenge.

To bypass the limitations of the --format option, the index function offers a solution. This function allows users to retrieve values from a map-like structure based on a specified key.

In the bash script, the following syntax can be utilized:

docker inspect -f '{{ index .Config.Labels "com.wherever.foo" }}' <image-name>

This command will return the value associated with the label "com.wherever.foo" from the JSON output of the docker inspect command.

The above is the detailed content of How to Access Docker Image Labels with Periods in Their Names?. 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