Creating a Private Repository and Push an Image to That Private Repository
Last Updated :
17 Feb, 2023
In this article, we show how to create a docker hub account and pull the image from the docker hub repository and push our image to the docker hub repository. As the docker hub is a public repository that can be accessed by anyone so one can create their own private repository to which they can push and pull their image. For this, there is a registry container from the docker itself.
Requirements
- Installed docker software in your respective operating system.
- A pulled image in your docker container which you want to push into your private repository.
Steps to create a private repository and push and pull the image:
Step 1:The first step is to use the docker run command to download the private registry.
sudo docker -d -p 5000:5000 --name registry:2
Description of commands:
- -d: This option is used to run the container in detached mode i.e the container can run in the background.
- -p: This option is used to map our port number with 5000 port numbers on our localhost.
- registry: It is a container provided by docker to host our private repositories.
- 2: It is a tag to a registry to differentiate on the docker host.
You can use the docker ps command to see the running registry container.
sudo docker ps
Step 2: In this step, we are going to tag our existing image so that we can push that image to our local repository.
sudo docker tag image_id tag_name
Description of commands:
- image_id: The id of the image you want to push to your private repository.
- tag_name: The name you want to give to your tag.
Step 3: We have tagged our image now it is ready to push to the private repository.
sudo docker push tag_name
Step 4: Now delete the local images so that we can pull it from a private repository. To delete the image use rmi command.
sudo docker rmi image_id
Step 5: In the previous step, we deleted all the images now we pull the image from the private repository by the docker pull command.
sudo docker pull image_tag
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...