Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a Docker image's label if the label name has a "." in it?

The docker inspect command can be very useful for getting the labels on a Docker image:

# -*- Dockerfile -*-
FROM busybox
LABEL foo="bar"
LABEL com.wherever.foo="bang"

For simple label names, the inspect command has a --format option (which uses Go templates) that works nicely.

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

But how do I access labels that have a dot in their name?

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

I'm writing this in a bash script, where I'd like to avoid re-parsing the JSON output from docker inspect, if possible.

like image 834
leedm777 Avatar asked Nov 24 '15 03:11

leedm777


People also ask

How do I get a docker image label?

To check the labels of a particular Image, you can use the Docker Inspect command. Start the Docker Container. Execute the Inspect Command. Inside the LABELS object, you can find all the labels associated with the image that you have specified inside your Dockerfile.

Can Docker image name contain?

A docker tag name must be valid ASCII and may contain lowercase and uppercase letters, digits, underscores, periods, and dashes. A tag name may not start with a period or a dash and may contain a maximum of 128 characters. You can group your images together using names and tags.

What is Docker object labels?

A label is a key-value pair, stored as a string. You can specify multiple labels for an object, but each key must be unique within an object. If the same key is given multiple values, the most-recently-written value overwrites all previous values.


1 Answers

The index function is what I was looking for. It can lookup arbitrary strings in the map.

$ docker inspect -f '{{ index .Config.Labels "com.wherever.foo" }}' foo
bang
like image 118
leedm777 Avatar answered Sep 28 '22 11:09

leedm777