Creating Docker Tags

The source files that are used to manage Docker containers are known as Docker images. These Docker images provide instructions to the container for managing and deploying projects. Developers work on several projects, and they occasionally need to update them. For this purpose, they also need to upgrade the Docker images. In such scenarios, it is required to specify the version of the Docker image. Thanks to Docker “tags”, which help us specify the various versions of Docker images.

In this write-up, we will demonstrate:

How to Create Image in Docker?

To create an image in Docker, first, create a simple Dockerfile. Then, utilize the “docker build” command to create a new Docker image. To do so, go through the provided instructions.

Step 1: Create Dockerfile

Create a simple Dockerfile to run a simple Python program. The file name must be stored as “Dockerfile”:

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

Step 2: Create Program File

Next, create another file named “” with the program code:

print("Hello, Welcome to Linuxhint tutorial")

Step 3: Build Docker Image

Build the new Docker image through Docker “build” command. Here “-t” option is used to specify the image name:

> docker build -t py-img .

Step 4: Build New Tagged Image

Users can also specify the image version or tag the image while creating a new image using the provided command. Here, the image name is specified as “image-name:tag”:

> docker build -t py-img:3.6 .

Next, list down all images to verify if the Docker image is created or not:

> docker images

It can be observed that we have successfully created a docker image along with the tag “3.6”:

Note: If we do not specify the tag of the image, then the default value of the tag will be set as “latest”.

How to Tag Docker Image?

The version of an image can be specified using the Docker “tag” command. Developers often upload images to the Docker registry with the same name. However, updated images can be identified by unique versions. The syntax used to tag the image is as follows:

> docker tag <image-id> <new-image-name>:<tag>

Look at the provided instructions to tag the images in Docker.

Step 1: List All Images

First, list down all images and note the id of the image you want to tag:

> docker images

Step 2: Tag the Image

Utilize the “docker tag” command along id of the image you want to tag, the new image name, and tag value:

> docker tag 13a1fc262da5 python-img:3.6

Again, list down the Docker image to confirm if the image is tagged or not:

> docker images

Step 3: Tag the Already Tagged Image

You can also tag the image which is already tagged, as shown below:

> docker tag py-img:3.6 py-img:5

We have demonstrated how to create and tag images in Docker.


Docker “tag” command is used to specify the version of the image or tag the image. Users can also specify the image version while building the new image. To tag the already built image, utilize the “docker tag <image-id> <new-image-name>:<tag>” command. This write-up has demonstrated how to Docker an image and how to tag the image.

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.