Get Labels Without Pulling Docker Images
Posted onFor whatever reason, there will be occasions when you want to view the labels for a Docker image.
Typically you would run docker inspect
to do this however that only works for local images.
Here’s what you can do to view the labels for remote Docker images.
To view the labels for a Docker image, the image needs to be pulled first. For example, to view the labels for an image you already have locally:
|
|
where <MY_IMAGE>
is the name and tag of the local image.
Retrieving labels for remote Docker images
You can get the labels for a remote Docker image (on Docker Hub) via the registry API. This is a few involved steps including getting a token, then retrieving the latest manifest for that image, getting the digest SHA, and then using that to get a map of labels. Or you can use a one-liner with a tool called Sonar.
I introduced Sonar a few months ago and with the v0.10.0 release labels can now be listed for a remote image. You can list all labels for an image or just a single one by specifying the key. Here’s an example using the GoReleaser Docker image:
|
|
I hope this is helpful. You can learn how to download and install Sonar and contribute at its GitHub Repository.