Episode 12. Naming and Tagging Docker Images and Containers

Amir Mustafa
3 min readFeb 27, 2022

--

In this article, we will learn how to add names to docker containers and images

In previous episodes, we have used randomly assigned names or container IDs for docker commands.

1. Naming a Docker Container:

→ By default, when we create a container, a random name is assigned to it.

→ It would be great if we could assign names ourselves, we then don’t have to get ID or name from the list, we would remember it.

docker ps -a                 // check all containers in docker
docker run <docker-image-id> // create a container

→ We observe some random names is assigned by docker (eg. optimistic wozniak)

→ We add a name flag for adding custom name

docker run --name <my-container-name> <docker-image-id> eg. docker run --name node-feb-2022 f45df32be90022c8c

→ Let us run the view docker container command again

docker ps -a    // Check all containers in docker

→ The beauty of naming convention is we do not need to check the ID or random name now. We can directly start/stop the container with our assigned name.

2. Naming a Docker Image:

For naming a docker image, we have two attributes for this

→ To check docker images, we run the below command:

docker images     // gives us list of images
docker build . // create docker images

→ Image has two sections — repository (i.e. name) and tag (i.e. version)

→ We observe, only the one downloaded from Docker Hub has names, the rest do not have.

→ To assign names in image we use -t flag

docker build -t <image-name>:<image-tag> .eg. docker build -t node:17 .

→ This time we see our image name and tag assigned 😀

Video:

Closing Thoughts:

It is difficult to remember the ID of multiple containers. If we assign a name to our docker image or container, we will remember it for a long time.

Official images in Docker Hub have names assigned by default eg. node, node: latest, node:14. It is a good practice to assign names as shown in the last image.

Thank you for reading till the end 🙌 . If you enjoyed this article or learned something new, support me by clicking the share button below to reach more people and/or give me a follow on Twitter and subscribe Happy Learnings !! to see some other tips, articles, and things I learn about and share there.

--

--

Amir Mustafa
Amir Mustafa

Written by Amir Mustafa

JavaScript Specialist | Consultant | YouTuber 🎬. | AWS ☁️ | Docker 🐳 | Digital Nomad | Human. Connect with me on https://www.linkedin.com/in/amirmustafa1/

No responses yet