I know that there is a LABEL available in Dockerfile. But I was wondering how to add additional labels to the image after it is built? Is this possible?
I know that there is a LABEL available in Dockerfile. But I was wondering how to add additional labels to the image after it is built? Is this possible?
It's indeed not possible to add a label to an existing image. Strictly speaking, adding a label would change the images checksum, thus its id, thus it's no longer the same image.
But you can build an image based on your existing image with a label added, and then tag this image with the name of the previously existing image. Technically it adds a layer on top of your existing image and thus just "overrides" previous labels.
It's also possible to do this with a single command. Given you want to add a label to the image "debian:latest", you build FROM that image and tag the new image at the same time.
echo "FROM debian:latest" | docker build --label my_new_label="arbitrary value" -t "debian:latest" -
Proof that "adding" the label worked:
$ docker inspect -f "{{json .Config.Labels }}" debian:latest
{"my_new_label":"arbitrary value"}