Docker - Private Registries


Advertisements

You might have the need to have your own private repositories. You may not want to host the repositories on Docker Hub. For this, there is a repository container itself from Docker. Let’s see how we can download and use the container for registry.

Step 1 − Use the Docker run command to download the private registry. This can be done using the following command.

sudo docker run –d –p 5000:5000 –-name registry registry:2

The following points need to be noted about the above command −

  • Registry is the container managed by Docker which can be used to host private repositories.

  • The port number exposed by the container is 5000. Hence with the –p command, we are mapping the same port number to the 5000 port number on our localhost.

  • We are just tagging the registry container as “2”, to differentiate it on the Docker host.

  • The –d option is used to run the container in detached mode. This is so that the container can run in the background

Detached Mode

Step 2 − Let’s do a docker ps to see that the registry container is indeed running.

Docker PS

We have now confirmed that the registry container is indeed running.

Step 3 − Now let’s tag one of our existing images so that we can push it to our local repository. In our example, since we have the centos image available locally, we are going to tag it to our private repository and add a tag name of centos.

sudo docker tag 67591570dd29 localhost:5000/centos 

The following points need to be noted about the above command −

  • 67591570dd29 refers to the Image ID for the centos image.

  • localhost:5000 is the location of our private repository.

  • We are tagging the repository name as centos in our private repository.

Private Repository

Step 4 − Now let’s use the Docker push command to push the repository to our private repository.

sudo docker push localhost:5000/centos 

Here, we are pushing the centos image to the private repository hosted at localhost:5000.

Localhost

Step 5 − Now let’s delete the local images we have for centos using the docker rmi commands. We can then download the required centos image from our private repository.

sudo docker rmi centos:latest 
sudo docker rmi 67591570dd29

Docker RMI Commands

Step 6 − Now that we don’t have any centos images on our local machine, we can now use the following Docker pull command to pull the centos image from our private repository.

sudo docker pull localhost:5000/centos

Here, we are pulling the centos image to the private repository hosted at localhost:5000.

Pulling Centos Image

If you now see the images on your system, you will see the centos image as well.

Advertisements