Docker

How do I Tag a Docker Image as Latest?

Docker images are the essential component of the Docker platform that plays with Docker containers to containerize users’ applications. These images are simple text files that instruct containers on managing, building, and deploying applications within containers. Developers modify images and applications and release new copies or updates of Docker images, represented by unique tags.

This blog will demonstrate how to tag the Docker image as the latest.

How to Tag a Docker Image as the Latest?

Docker “tag” command is widely used to tag images. However, users can directly tag the image while building the new Docker image. If the tag is not set during image creation, it is considered “latest”.

For the proper guideline, we have listed some methods:

    • Method 1: How to Tag Docker image as Latest While Building Image?
    • How to Tag Docker Image as Latest Using “docker tag” Command?

Method 1: How to Tag Docker image as Latest While Building Image?

To tag the Docker image as the latest while building a new Docker image, go through the given steps.

Step 1: Create Dockerfile

First, create a Dockerfile that specifies simple instructions to execute the Python program:

FROM python:3.6
WORKDIR /src/app
COPY . .
CMD [ "python", "./Python.py" ]

 

Step 2: Build Docker Image

To build the Docker image, run the given command. Here, “-t” is used to tag or name the image, and “-f” is used to read the Dockerfile forcefully. Moreover, the “-f” option is usually used when users are required to provide the path along with the Docker file:

> docker build -t py-img -f Dockerfile .

 

View the Docker image to verify if the image is created and tagged as “latest” or not:


Build Docker Image and Tag it as Latest

To tag the Docker image as the latest while creating a new image, utilize the “docker build” command along with the “-t” option and specify the image name as “image-name:tag”:

> docker build -t py-img -f Dockerfile .

 

List down all images and verify if the image is tagged as the latest or not:

> docker images -a

 
It can be observed that the image is tagged as the latest:

Method 2: How to Tag Docker Image as Latest Using “docker tag” Command?

The docker “tag” command is particularly used to tag the Docker images. To tag the Docker image as the latest, utilize the “docker tag <old-image> <new-image>:<tag>” command:

> docker tag py-img py-img:latest

 

Again, verify if the image is tagged or not by utilizing the “docker images” command:

> docker images

 

This is all about how to tag the Docker image as the latest.

Conclusion

To tag the Docker image as the latest, users can utilize the “docker tag <old-image> <new-image>:latest” command. However, you can also tag the image while building the new Docker image. For this purpose, utilize the “docker build -t <image-name>:<tag> .” command. This blog has demonstrated how to tag the Docker image as the latest.

About the author

Rafia Zafar

I am graduated in computer science. I am a junior technical author here and passionate about Programming and learning new technologies. I have worked in JAVA, HTML 5, CSS3, Bootstrap, and PHP.