Confused with the concept of docker tags

374 Views Asked by At

I am going through a books and came across this line:

Whereas a tag can only be applied to a single image in a repository, a single image can have several tags. For example, the Java repository on Docker Hub maintains the following tags: 7, 7-jdk, 7u71, 7u71-jdk, openjdk-7, and openjdk-7u71. All these tags are applied to the same image.

My question is: why will a single image have several tags? What is the purpose of tagging the same image with different tags?

2

There are 2 best solutions below

0
On

In my opinion there are mainly two reasons.

First of all, it is for convenience, so you may give multiple aliases to the same images.

But you can give other (special) tags to images in order to push it to a different registry.

Suppose (for example) you are using microk8s and you enabled the registry service. To push a local image of yours, you have to apply it with a tag formerly named localhost:32000/my-image:my-tag.

In that scenario your image will have two tags my-image:my-tag and localhost:32000/my-image:my-tag. So, to push it to microk8s registry the only thing you will have to do is to issue the command git push localhost:32000/my-image:my-tag (the image tag will be parsed to get the URI of the registry to push to).

The above concept, obviously, can be applied to any other remote registry.

0
On

You can use multiple tags for all sorts of purposes. The most popular one is to have a "latest" image, for example.

Imagine you're pulling the latest ubuntu image. That would be "docker pull ubuntu:latest". Try pulling ubuntu:20.04 - you'll find out you have already pulled the image.

NOTE: After a while, ubuntu:latest won't be the same a ubuntu:20.04 anymore, but to the newest tag. However, you'll always have a pointer to the latest version of the ubuntu image and wherever you're using it, you won't need to change the tags.