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.
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>
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!