You can also create and upload your images on the Docker Hub public registry. But, these images become public, and anyone can access and use your images. So, it is recommended to use Docker private registry that allows you to control and protect your images. In this tutorial, I am going to explain how to set up a Docker private registry on Ubuntu 18.04.

Requirements

Two Ubuntu servers with the root credentials A static IP address on both servers

Getting Started

Before starting, you will need to configure hostname resolution on both systems. So, both system can communicate with each other by hostname. To do so, run the following command on both systems: Once you have finished, you can proceed to the next step.

Install Docker

Next, you will need to install Docker package on both systems. By default, Docker is not available in the Ubuntu 18.04 default repository. So, you will need to add them. First, install the required packages with the following command: Next, add the Docker repository with the following command: Next, update the repository and install Docker with the following command: Once the installation has been completed, check the status of docker with the following command: You should see the following output:

Install Docker Registry Container

First, you will need to install Registry container on your server system. You can do it by running the following command: Once the registry image has been downloaded, you should see the following output: Next, start the registry container with the following command: You can see the running registry container with the following command: You should see the following output:

Create a Docker Container Image on the Client System

Your registry server is now ready to use. It’s time to create a Docker container image on the client system. First, log in to the Client system and create a dockerfile to build Nginx web server image: Add the following lines: Save and close the file. Then, build an Nginx image by running the following command: After building the Nginx image successfully, you should see the following output: Next, you can check the generated image with the following command: You should see your nginx image in the following output: Next, you will need to rename your nginx image in “registryserver:portnumber/image name:tag” format. You can do it with the following command:

Upload Nginx Image on Private Registry Server

You can now upload your generated Nginx image on Private Registry Server using the push command: Once the image uploaded successfully, you should see the following output: You can also download the uploaded image from the registry server with the following command: I hope you have now enough knowledge to set up your own private docker registry server on a production server. If you are looking to get more Docker hands-on, then check out this online course.