Docker

How to Change Repository Name or Rename Docker Image

Docker is a set of forums as a service (PaaS) product that are used the OS level virtualization to deliver an application in packages known as containers. It is specially designed to generate, deploy, and execute the applications in containers. Containers are executed by a single operating system kernel and therefore use fewer resources as compared to a virtual machine.

The outcomes from this tutorial are:

What is Docker Repository\Container?

Docker containers are software packages that offer an isolated environment to developers for executing their code/applications. Basically, containers have no knowledge of the developer’s OS or their files. All the application’s dependencies and its interface are completely abstracted from other containers. Docker Desktop provides the environment to users for execution. Docker containers also minimize the vulnerability, the Docker container gets crashed or infected by malware, and the other will not crash.

How to Rename a Repository or Container in Docker?

To change the name of the repository or container in Docker, check out the following steps.

Step 1: List Docker Containers

First of all, view the status of the currently running processes through the provided command:

docker ps

As you can see, currently the new_container and gifted_bhaskara Docker containers are active. Now, choose the desired container which needs to be renamed. Here, we have selected the 5e81d2bc01a5 container id for further process:

Step 2: Change Docker Container Name

Next, execute the docker rename command to change the container’s name:

docker rename 5e81d2bc01a5 local_container

Here, the 5e81d2bc01a5 is the existing container id and local_container is the new name of the container:

Step 3: Verify Renamed Docker Container

To verify whether the name of a particular container has been changed or not, use the following command:

docker ps

According to the provided output, the Docker container renamed successfully:

What is Docker Image?

A Docker image holds all the necessary instructions and is utilized for executing the Docker containers, such as templates. Docker image is also used as the initial point when working with Docker. It is comparable to a snapshot in virtual machine environments.

How to Rename the Docker Image?

Now, try out the following institutions to modify the Docker image name.

Step 1: Check Docker Images

Run the docker images command to view all available Docker images:

docker images

From the below-given output, we have selected the demo1 image for further use:

Step 2: Rename Docker Image

Next, execute the provided command to update the existing image name:

docker tag demo1:latest elicimage:v2

In the above-stated command:

  • docker tag command is utilized for changing the image name\tag.
  • demo1 is the previous Docker image name.
  • latest is a tag of the existing Docker image.
  • elicimage is a new Docker image name.
  • v2 is a tag of the new image:

Step 3: Verification

Now, verify if a previously selected name has been updated or not:

docker images

As you can see, it’s renamed successfully:

Step 4: Remove Old Image

Next, delete the old image from Docker by running the following command. Here, we have provided the image name along with its tag:

docker rmi demo1:latest

After executing the above command, the particular image has been untagged successfully:

How to Add Docker Images into a Private Repository?

In Docker, users can push an image to their private repository. To do so, they need to tag the image with the repository name by using the following command:

docker tag elicimage:v2 mari422/demo1

In the above-provided command:

  • docker tag command utilized for tagging the Docker images.
  • elicimage is the image and v2 is a tag name.
  • mari422/demo1 is the Docker’s Hub private repository name:

Then, run the docker push command to push the Docker image into the Docker registry:

docker push mari422/demo1

According to the following output, the Docker image has been pushed into a private repository:

That’s it! You have learned the easiest procedure of modifying the container name and renaming the Docker image.

Conclusion

Docker repositories are software packages that offer an isolated environment to users for executing their code/applications. They can rename it by using the docker rename <old-iamge-name> <new-iamge-name> command. While a Docker image holds instructions and helps developers to run the Docker containers. To rename the Docker image, the docker tag <image-name:image-tag> <user-name/repo-name> command is used. This tutorial elaborated on changing the repository name or renaming the Docker image.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.