You can use Image tags to describe an image using simple labels and aliases. Tags can simply be the version of the project, features of the Image or simply your name, pretty much anything that can describe the Image. It helps you in managing the version of the project and allows you to keep track of the overall development process.
In this article, we will discuss almost everything related to tags that would help you get started with Image Tagging.
Before diving into this article, let’s discuss something called the latest tag. If you don’t specify a tag to an image, it automatically gets tagged with the latest tag meaning that this Image is of the latest version.
The three most common scenarios where tagging is mostly used that are described below:
1. While Building the Image
You can specify a tag to the image right at the time when you are building it using the -t flag. If you don’t specify a tag, it is automatically tagged with the latest tag.
sudo docker build -t <image-name>:<tag-name>
You can also specify the tag of the Image which you want to pull in the Dockerfile. Let’s say you have a Dockerfile to pull an Ubuntu Image with the latest version.
Now, if you want to build the Image with a custom tag called my-ubuntu, you can use the following command.
sudo docker build -t tag-demo:my-ubuntu .
2. Tagging the Image directly
You can also tag an Image directly using the tag sub-command.
sudo docker tag <imageId> <imageName>/<tagName>
You can see that the new tag has been assigned to the Image.
3. While Pulling an Image
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.
sudo docker pull alpine:3.6
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.