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?
If you are consistent if putting the Dockerfile in a directory with the same name as you want for your image, you can use docker build -t $(basename $PWD) . as your build command. Then you can use CTRL-R search from "build" to find and reuse the command and never have to edit it.
Latest is Just a Tag It's just the tag which is applied to an image by default which does not have a tag. Those two commands will both result in a new image being created and tagged as :latest: # those two are the same: $ docker build -t company/image_name . $ docker build -t company/image_name:latest .
Docker tags are just an alias for an image ID. The tag's name must be an ASCII character string and may include lowercase and uppercase letters, digits, underscores, periods, and dashes. In addition, the tag names must not begin with a period or a dash, and they can only contain 128 characters.
You can pull a Docker Image using the pull sub-command. You can specify the tag of the Image that you want to pull. Note that if you don't specify a tag, it will automatically pull the latest version of the Image by appending the “latest” tag to the Image.
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"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With