The outcomes from this tutorial are:
- What is Docker Repository\Container?
- How to Rename a Repository or Container in Docker?
- What is Docker Image?
- How to Rename the Docker Image?
- How to Add Docker Images into a Private Repository?
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:
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:
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:
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:
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:
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:
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:
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:
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:
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.