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.
The
index
function is what I was looking for. It can lookup arbitrary strings in the map.