Docker

How to Name or Rename Docker Containers

Docker is a well-known technology for project development and deployment. It introduces the concept of Docker containerization for project deployment. Containers are a fundamental Docker component that contains all dependencies and libraries required for project deployment. When users generate a Docker image, a new container is built automatically, and developers can now name or rename the container.

This post will demonstrate how to name or rename a Docker container.

How to Name or Rename Docker Container?

To name or rename a container, create a container through the Docker images and specify the container name. Developers can also rename the container name later using the “docker rename <old-name> <new-name>” command.

Step 1: Open Terminal

First, open your favorite terminal from the Windows Start menu. For instance, we will use the “Git Bash” terminal:

Step 2: Open Project Directory

Utilize the “cd” command to open the project directory:

$ cd "C:\DockerDemo"

List down all files and directories using the “ls” command. Here, you can see we have a Dockerfile. The Docker file contains all instructions that will create a Docker image to instruct the container:

$ ls

Step 3: Build a Docker Image

Now, build the Docker image with the help of provided command:

$ docker build -t demo .

Step 4: Create a New Container

In order to build a new container using the newly created Docker image, utilize the “docker container create” command. Here, “i” is used as the interactive flag, the “-t” option is utilized to allocate a pseudo tty terminal that helps in connecting with the container, and the “–name” flag is used to name the container:

$ docker container create -i -t --name New-container demo

Let’s see if the container was created or not by running the “docker ps -a” command:

$ docker ps -a

Step 5: Rename a Container

In order to rename the container, the “docker rename” command can be effective enough:

$ docker rename New-container Docker-container

Again, check the container list to verify if we have successfully renamed the container or not:

$ docker ps -a

We have demonstrated how to name and rename Docker containers.

Conclusion

To name or rename the Docker container, first, create a new Docker image by utilizing the Dockerfile. After that, create a new container and name the container using the “docker container create -i -t –name <container-name> demo” command. In order to rename the container, use the “docker rename <old-name> <new-name>” command. We have elaborated on how to name or rename a Docker container.

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.