This article will explain:
- Is it possible to have multiple tags for an image?
- How to build an image with Various tags?
- Tag images in Docker
Is It Possible to Have Multiple Tags for an Image?
Yes, it is possible for a Docker image to have multiple tags. As in Docker, images are updated from time to time according to requirements, just like application updates. For this purpose, users need to specify the specific version of the image or a unique tag for identification. Therefore, the Docker image can have multiple copies of an image along with unique tags.
How to Build an Image With Various Tags?
You can build the same image with multiple tags while building the image from a Dockerfile. For this purpose, go through the given instructions.
Step 1: Make Dockerfile
First, make a simple file named “Dockerfile”. Then, paste the below-coded instruction into Dockerfile:
WORKDIR /src/app
COPY . .
CMD [ "python", "./pythonapp.py" ]
The above instructions build an image to execute a simple python program that is defined in the “pythonapp.py” file:
Step 2: Built an Image With Multiple Tags
Next, utilize the “docker build” to generate the image with multiple tags. Users can utilize the “-t” or “–tag” option to build multiple tag images. For instance, to create an image with three different tags, we have to use the “-t” option three times:
Step 3: Verification
Now, verify if the image has been created with the specified tags:
Tag Images in Docker
However, users can tag an image multiple times. In other words, you can specify the different tags for a single or similar image. For this purpose, the “docker tag” can be utilized.
Follow up on the below-mentioned procedure to tag the image in Docker.
Step 1: Tag the Image
To tag the image to specify the version of the image, utilize the “docker tag <original-image-name> <target-image-name>:<tag>” command:
In the above command, we have tagged the “python:latest” image as “python:2.4”:
You can tag a single image many times to specify the multiple tags of an image. For instance, we have again tagged the “python:latest” image as “python:2.8”:
Step 2: Verify If the Image is Tagged
Next, check out all images in Docker to verify it the newly tagged images are created or not:
It can be observed that we have defined the two tags for “python:latest” image.
Conclusion
Yes! It is possible for an image to have multiple tags. As the images are updated from time to time and users must be required to assign unique identifying tags to an image. However, you can build the same image with multiple tags using the “docker build -t <image-name> -t <image-name>:tag” command. To create an image of multiple tags, use the “-t” option multiple times. This blog has illustrated that it is possible for an image to have different tags.