Working With The Container Tags

The container tags help us easily handle and work with our containers rather than always using their ID at the time of approaching. This also helps us to have an idea about which container we are working on.

  • In the container host machine, open up the PowerShell and get into the directory in which we have previously created our Dockerfile and the websrc.

  • Now, open the websrc folder and edit the HTML file with some new data indicating that this website is the second version and save it.

    Windows PowerShell

  • Now, in PowerShell, run the command to build the image from the Dockerfile again. But this time, we are going to name it with a new tag as well the website that is hosted will be version two. Use the following command:

    docker build -t web:version2
  • Now, this has created a new image with the second version of our website. This time, the deployment of our image took much less time because Step 3 has proceeded from the cache which was stored during the previous execution.

    Windows PowerShell
  • Now, get all the available images by running the images command:

    docker images

    Windows PowerShell
  • We shall try changing the tag name of the image named container with the latest tag. Run the following code.

    docker tag web:latest web:version1
  • Now again, run the command docker images to get all the images and you will find that the tags of the images are being changed. Here, you will be having the same image with different tag names and a common image ID.

    Windows PowerShell

  • We shall now remove the old tag name by running the command:

    docker rmi web:latest

    Windows PowerShell
  • Again, run the docker images command to get the images. Now, you can find different tag names for the two different images.

    Windows PowerShell

  • Now, try changing the tag version 2 to latest and remove the old tag. This is how we can work with the tag names of the containers.

  • These container tags can be used to work with the container images. Now, try running any one of these images by using their tag name. Run the below code and check it. You can work with the containers.

    docker run -it web:version2

    Windows PowerShell

    Windows PowerShell
This is how we can handle the tag names. With these tag names, we can work with the container images.

Up Next
    Ebook Download
    View all
    Learn
    View all