Setting Up A Private Indexregistry

Earlier, we used a Docker-hosted registry (https://hub.docker.com) to push and pull images. Nonetheless, quite often you will come across use cases where you will have to host a private registry in your infrastructure. In this recipe, we will host our own private registry using Docker’s registry:2 image.

Getting ready

Make sure that Docker daemon version 1.6.0 or above is running on the host.

How to do it…

Perform the following steps:

  1. Let’s begin by launching a local registry on the container using the following command:
$ docker container run -d -p 5000:5000 \
                           --name registry registry:2
  1. To push the image to the local registry, you need to prefix the repository name with the localhost hostname or the IP address 127.0.0.1 and the registry port 5000 using the Docker image tag command, as shown in the following code:
$ docker tag apache2 localhost:5000/apache2

Here, we will reuse the apache2 image we built in the previous recipe.

  1. Now, let’s push the image to the local registry using the docker image push command, as shown in the following screenshot:

Diagrama

How it works…

The preceding command to pull the image will download the official registry image from Docker Hub and run it on port 5000 . The -p option publishes the container port to the host system’s port. We will explore details about port publishing in the next chapter.

There’s more…

The registry has a notification framework that can invoke WebHooks when it receives a push or pull request. These WebHooks can be chained with your DevOps flow.

See also