Docker basics: using docker image tags effectively

Docker image can use several image tags for the same image. Docker image tags are usually used for versioning. It informed that there is more than one choice of the version available in the image. We can choose any image tags available.

If we don't specify any tags, then docker will assign latest as the tags. But it's considered bad practice. In order to avoid that, we're gonna use versioning on the image tag. Let's say that we're going to use tags like V1 or V2, that's also okay. But let's use some other practice that many software use.

Many projects out there use numeric versioning with decimal point to indicate how big the change there is between image tags and version. The basic idea is something like [major].[minor].[patch]. Depends on which part that change between version, it can indicate some change or different.

The increment in patch number may tell us that there's not much difference between this version and the last version. It may have some minor bug fix. But overall, there'll be no breaking change or feature added to it.

The increment in minor number may tell us that there'll be a new feature added or changed. But there'll be no breaking change.

The increment in major number may tell us that there'll be a huge difference between this version and last version. There'll be a whole new different feature, different behaviour, and breaking change.

So, if we use this same approach in creating our docker image, we can give our user an option to pick whichever version they want or just the latest release. This image below shows us that user can pull whichever version that they want to use:

image.png

Let's say that the user is pulling our image version 2.0 using this command:

docker pull image:2.0

What really happens is, the user is pulling our image version 2.0.4. It means that, without specifying the patch number in a tag, Docker will pull the latest release of that patch from the minor version. So, pulling version 2.0, in reality, will pull version 2.0.4.

That's also going the same for a major release. If the user is only pulling an image using the major release tag like the command below:

docker pull image:2

Then docker will actually pull the version of 2.0.4. It means that Docker will pull the latest release tag of that major version. This is the typical versioning that we'll often see when using Docker image in any registry.

So it's really important to specify the image tag inside our Dockerfile. And if we don't specify the tags, in the worst case, when the new release comes out, it can break our app.