How to Setup Docker Private Registry on Ubuntu 16.04

By Hitesh Jethva, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Docker private registry is a highly scalable server-side application that can be used to store and distribute the Docker images internally within your organization. Docker also has its own public registry (Docker Hub) that allows you to store Docker images. But, the images you upload on Docker Hub becomes public. Anyone can access and use your images from Docker Hub. So it is not the best option for your organization. Docker private registry allows you to set up a Docker registry for your project privately so that only your organization can store and use Docker images on it. Using Docker private registry, you can easily control your images, fully own your images distribution pipeline, and integrate image storage and distribution tightly into your in-house development workflow. If you want to quickly deploy a new image over a large cluster of machines, then Docker private registry is the best solution for you.

In this tutorial, we will explain how to set up our own Docker private registry server on two Alibaba Cloud Elastic Compute Service (ECS) instances with Ubuntu 16.04.

Requirements

  1. A new Alibaba Cloud instance for registry server with Ubuntu installed.
  2. A new Alibaba Cloud instance for registry client with Ubuntu installed.
  3. A static IP address 192.168.0.101 is set up on the registry server instance and 192.168.0.102 is set up on the registry client instance.
  4. A Root password is setup on the server.

Launch Alibaba Cloud ECS Instance

First, log in to your https://ecs.console.aliyun.com">Alibaba Cloud ECS Console. Create a new ECS instance, choosing Ubuntu 16.04 as the operating system with at least 2GB RAM. Connect to your ECS instance and log in as the root user.

Once you are logged into your Ubuntu 16.04 instance, run the following command to update your base system with the latest available packages.

Configure Host

First, you will need to setup /etc/hosts file in each instance, so each instance can communicate with each other using hostname.

You can setup /etc/hosts file on each instance with the following command:

Add the following lines:

Save and close the file, when you are finished.

Next, you can verify name resolution by running the following command on registry-server instance:

Install Docker

Before starting, you will need to install Docker on both instance. By default, the latest version of Docker CE is not available in the Ubuntu 16.04 default repository. So you will need to add Docker CE repository to your system.

First, install the following packages to your system.

Next, download and add Docker CE GPG key with the following command:

Next, add the /var/lib/dpkg/lockDocker CE repository to APT:

Finally, update the repository and install Docker CE by running the following command:

Once the installation is completed. Check the status of Docker with the following command:

Output:

Install Docker Registry

Before starting, you will need to Docker private Registry on registry-server instance. First, download the registry image from the Docker Hub using the following command:

Output:

Once the registry image downloaded, you will need to generate a self-signed certificate for securing Docker Registry. Because, Docker node uses a secure connection over TLS to upload or download images to or from the private registry.

Go to the registry-server and run the following command to generate certificate:

Output:

You will need to copy generated ca.crt certificate to all registry client system for trusting this certificate.

Now, start Docker registry container with certificate information by running the following command:

You can now verify the running registry container using the following command:

Output:

Create a Docker Image on Regisry Client

Next, you will need to create and build a Docker container image on registry client for uploading it on the private registry server.

Here, we will build an Apache web server image based on Ubuntu 16.04 using Dockerfile.

First, create a Dockerfile using the following command:

Add the following lines:

Now, run the following command to build an Apache web server image using Dockerfile:

Output:

The above command builds a Docker image with name ubuntu:apachev1.0.

You can list out it with the following command:

Output:

Next, you will need to rename the docker image in “registryserver:portnumber/image name:tag” format.

You can rename the generated image using the following command:

Now, verify again with the following command:

Output:

Upload Docker Image on Registry Server

Now, the Docker image is ready on registry-client. Before starting, you will need to copy the ca.crt certificate from the registry-server to registry-client.

Go to the registry-client instance and run the following command:

Now, restart docker service with the following command:

Next, upload the docker image to private registry server using the following command:

Output:

You can also download the uploaded image from the registry server using the following command:

Output:

Congratulations! You have successfully setup Docker private registry server on Ubuntu 16.04. You can now easily upload and download Docker images to and from your registry server.

Reference:https://www.alibabacloud.com/blog/how-to-setup-docker-private-registry-on-ubuntu-16-04_594085?spm=a2c41.12143936.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store