Home >Backend Development >Golang >How to Access Docker Image Labels with Dots in Their Names?

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

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-09 07:08:02854browse

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

Accessing Docker Image Labels with Dots in Their Names

The docker inspect command provides a versatile means to retrieve information about Docker images, including their labels. However, accessing labels with dots in their names can present a challenge.

Using Basic Notation

For plain label names, the --format option with Go templates allows for straightforward label retrieval:

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

Accessing Labels with Dots

To access labels with dots, the Go template syntax falls short. However, the index function within a template can be employed:

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

The above is the detailed content of How to Access Docker Image Labels with Dots 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