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.
=== Create
[source,sh]
----
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
----
== Docker Hub
Docker Hub is a registry service on the cloud that allows you to download Docker images that are built by other communities. You can also upload your own Docker built images to Docker hub.
To run apache, you need to run the following command:
[source,sh]
----
docker run -p 8080:80 apache
Note the following points about the above command −
Here, apache is the name of the image we want to download from Docker hub and install on our Ubuntu machine.
-p is used to map the port number of the internal Docker image to our main Ubuntu server so that we can access the container accordingly.
----
=== Push
use the Docker push command to push the image to our private repository.
[source,sh]
----
docker push localhost:5000/myimage
----
=== Pull
use the following Docker pull command to pull image from our private repository.