How to apply tags in Docker

Posted by

Docker tags relay useful information about a specific image version.  Tags often than not look like “image_name:#” the part following the colon is your tag. 

When you run the docker run command and the image is not local it will go download the latest version.  In our example, that would be ubuntu 20.04.1 but what if we needed an older version of ubuntu and wanted to “tag” that version?  Below we will do a quick scenario leveraging the docker run command to deploy an Ubuntu container on version 16.04 and tagging it as such.

Best Practice:
Even though in the bottom example I am using the latest tag to describe the latest image, that doesn’t mean that this image will be the latest tomorrow. Get into a habit of putting the version tag so you don’t accidentally break an application in the future.

Step by step

$ docker run ubuntu cat /etc/lsb-release

As you can see we have successfully deployed a container running the latest version of ubuntu.

Go to docker hub and search for ubuntu

As you can see, you can see all the supported tages. 

$ docker run ubuntu:16.04 cat /etc/lsb-release

$ docker ps -a

By running the docker ps -a command we can see that the container was successfully run at version 16.04 and was tagged

Apply tags for versioning is simple and easy.  This method can also be applied to images as well as containers.  As always, I hope y’all found this useful.

Leave a Reply