Tag Matters!! Why Would You Tag Your Images?

We know that image name can include an optional tag.

In this lesson, we will discuss tags in a bit more detail and learn why they are important.

We knew that image names include a name and a tag. As a quick reminder, an image name is:

<reposit…


This content originally appeared on DEV Community and was authored by Vaibhav Thukral

We know that image name can include an optional tag.

In this lesson, we will discuss tags in a bit more detail and learn why they are important.

We knew that image names include a name and a tag. As a quick reminder, an image name is:

<repository_name>/<name>:<tag>
  • tag is optional; when missing, it is considered to be latest by default
  • repository_name can be a registry DNS or the name of a registry in the Docker Hub

While your images aren’t published to a registry, you don’t need to include a registry name. So, your image name is:

<name>:<tag>

The latest tag

I didn’t include a tag; therefore the default latest tag was used. For instance, the actual image name was test:latest when I ran the following command:

docker build -t test .

As long as you are creating simple software, running on a simple CI/CD pipeline, it can be fine to use the latest tag. In a simple scenario, you may:

  1. Update the source code
  2. Build a new image with the latest tag
  3. Run a new container with the newest image
  4. Kill the previous container

There’s a caveat with this however: when using the docker run test command on a distant machine (which actually means docker run test:latest), the distant machine has no means to know that there is a newer version of the hello:latest image.

You need to run the docker pull test command on the distant machine in order for the newest version of your image to be downloaded to that machine.

This may sound awkward, and that’s one reason for not just using the latest tag.

Why Would You Tag Your Images?

Other reasons come to mind once you become more serious with your CI/CD pipeline.

For instance, you may want any or all of the following features:

  • Be able to roll back to a previous version of an image if you detect a problem with the latest image.

  • Run different versions in different environments. For instance, the latest version in a test environment and the previous version in a production environment.

  • Run different versions at the same time, routing some users to the latest version and some to the previous versions. This is known as a canary release.

  • Deploy different versions to different users, and be able to run whatever version on your development machine while you support them.

These are all good reasons for tagging your images. If you ensure each released image has a different tag, you can run any of the scenarios mentioned above.

You’re free to tag your images however you want. Common tags include:

  • a version number, e.g. test:1.0, test:1.1, test:1.2
  • a Git commit tag, e.g. test:2cd7e376, test:b43a14bb

In order to apply a tag, just state it during your build command:

docker build -t hello:1.0 .

I recommend specifying the image tag. If you want to keep up to date with new releases of the base image, update the tag manually and make sure you test your image before releasing it.


This content originally appeared on DEV Community and was authored by Vaibhav Thukral


Print Share Comment Cite Upload Translate Updates
APA

Vaibhav Thukral | Sciencx (2024-07-22T17:40:32+00:00) Tag Matters!! Why Would You Tag Your Images?. Retrieved from https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/

MLA
" » Tag Matters!! Why Would You Tag Your Images?." Vaibhav Thukral | Sciencx - Monday July 22, 2024, https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/
HARVARD
Vaibhav Thukral | Sciencx Monday July 22, 2024 » Tag Matters!! Why Would You Tag Your Images?., viewed ,<https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/>
VANCOUVER
Vaibhav Thukral | Sciencx - » Tag Matters!! Why Would You Tag Your Images?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/
CHICAGO
" » Tag Matters!! Why Would You Tag Your Images?." Vaibhav Thukral | Sciencx - Accessed . https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/
IEEE
" » Tag Matters!! Why Would You Tag Your Images?." Vaibhav Thukral | Sciencx [Online]. Available: https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/. [Accessed: ]
rf:citation
» Tag Matters!! Why Would You Tag Your Images? | Vaibhav Thukral | Sciencx | https://www.scien.cx/2024/07/22/tag-matters-why-would-you-tag-your-images/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.