How to apply tags in Docker

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

Screenshot from the Apply Docker Image Tags walkthrough at step 1; the adjacent article text explains that $ docker run ubuntu cat /etc/lsb-release.

$ docker run ubuntu cat /etc/lsb-release

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

Screenshot from the Apply Docker Image Tags walkthrough at step 2; the step instructs the user to go to docker hub and search for ubuntu.

Go to docker hub and search for ubuntu

Screenshot from the Apply Docker Image Tags walkthrough at step 3, showing Docker Official Images; the step instructs the user to go to docker hub and search for ubuntu.

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

Screenshot from the Apply Docker Image Tags walkthrough at step 4; the step instructs the user to go to docker hub and search for ubuntu.

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

Screenshot from the Apply Docker Image Tags walkthrough at step 5, showing CONTAINER ID; the adjacent article text explains that $ 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

Summary:
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

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading