Creating your Private Docker Registry

While dealing with Docker containers, you typically pull images from a public registry like Docker Store or Docker Hub. There are some use case where you might want to use a local registry to pull images from, especially if you have proprietary code used in your custome images. As such, you have more control and security for your images and containers.

Fortunately, Docker makes it very easy to deploy a local Docker registry using the registry image, which can be found in Docker Hub.

By pulling and running a container from this image, you will have a fully functional local registry that your can use to pull and push images from and to.

In this post, two servers are acting as Docker hosts. On one server, we will get a local registry up and running using the image registry. We will then push some images to that local registry. On the second server, where no local image is available, we will use our local registry installed on the first server to pull some images.

We’re keeping things simple in this article as the goal is just to show the necessary steps to make a Docker local registry up and running. We’re not using any TLS certificate to secure the communication between Docker hosts and the registry. Bear in mind that using an insecure registry in production is not recommended. Only use this solution for isolated testing only.

Preparing the Prerequisites


First, we need to configure Docker to skip security checks for your registry on all your Docker hosts.

Create a file called daemon.json file in /etc/docker if it does not exist.

Then add the following content and save the file.

Finally, restart the Docker service to make this setting effective

We’ll also need to make sure the hostname resolution is working properly on both hosts. I have server1 and server2 used in this lab. My registry will be called registry.local and installed on server1, so the hosts file on both servers should look like this:

 

Installing the local registry


Start by pulling the registry from Docker Hub

By default, the local registry is configured to start and listen on port 5000 in the container, and we will expose the host port also as 5000. To install a local registry named registry, and make it running in the background, it is as simple as running the following command.

Check that the container is effectively running.

Our local registry up and running and we’re good to push to push images.

 

Pushing Images to the local registry


We have some images stored on our server, but these images are only visible to this host and we need to make them available to pull for other Docker hosts in our environment by pushing the ones we want to use to our local registry.

This will be done in two steps. The first one will be to tag the image with the REGISTRY_HOSTNAME:REGISTRY_PORT prefix. The command syntax is as below:

My registry name is registry.local. So to tag the ubuntu image as my-ubuntu, the command will be as follow:

The image full name will be registry.local:5000/my-ubuntu

The second step will be to push the image to the local registry using the following syntax.

Below command we’ll actually push the tagged registry.local:5000/my-ubuntu image to the local registry

We now have a local registry with one image that can be pulled from any Docker host in our environment.

 

Pulling images to the local registry


On my second server, where there is no image available I should be able pull the ubuntu image pushed previously, but let’s make sure hostname resolution to registry.local is working fine.

Let’s pull my-ubuntu image from registry.local:5000

Image pulled successfully and is available now locally on the second Docker host.

That’s it for this post. You have a fully functional private Docker registry that can be used in your environment. I a production environment, make sure your have a TLS certificate issues from a trusted CA for secure communication through HTTPS, and also attach a volume to your registry container to store your images in a permanent storage. My suggestion is to head over this Docker official documentation link and go through the content as it contains detailed information about this topic.

 

Find this post interesting. Share it!

Leave a Comment

Your email address will not be published. Required fields are marked *