How can we help?
Categories
< All Topics
Print

How to Host Your Own Docker Hub in ServerStadium

Docker is a popular container application to host an application on a container instead of a server. Docker has a free public registry named Docker Hub that can host custom Docker images.

But, there is a condition that a developer does not want his Docker image publicly available. And the Docker Registry exists to meet that condition. Docker Registry is an application that manages, stores, and delivers container images in a private environment.

Here are the steps to host the Docker Registry environment or hub in ServerStadium using Ubuntu Virtual Machine.

Prerequisites

  • Two Ubuntu VM’s acted as private Docker Registry server and the other as a client. In this tutorial, there are 2 VM’s :
    Docker Registry – 198.167.141.168 – dockerhub1
    Client – 202.43.249.219 – dockerhub2
  • Docker and Docker-Compose installed on both VM’s.

Step 1 – Installing and Configuring the Docker Registry

To begin with is make a container that contains Docker Registry application running on Docker Registry server with port 5000 (this is optional), with the command :

# docker run -d -p 5000:5000 --restart=always --name registry registry:2

Then, pull an image from Docker Hub, for example, like Alpine image like the below :

# docker pull alpine:latest

If the pulling process is successful you will get output like the below :

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
alpine        latest    389fef711851   10 days ago     5.58MB

Give a new tag into that Alpine image based on Docker Registry location, in this case, is localhost, with the command :

# docker tag alpine:latest localhost:5000/alpine:latest

If you are running the “docker images” once again, you will get a result like this :

REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
localhost:5000/alpine   latest    389fef711851   10 days ago     5.58MB

After that, push that custom image into Docker Local Registry, with the command :

# docker push localhost:5000/alpine:latest

If successful, those custom Docker Images will be saved into your own made Docker Registry server.

The push refers to repository [localhost:5000/alpine]
777b2c648970: Pushed 
latest: digest: sha256:074d3636ebda6dd446d0d00304c4454f468237fdacf08fb0eeac90bdbfa1bac7 size: 528

Step 2 – Pulling Images from the Docker Registry Server

Move the environment into the client VM. And then continues the steps by pulling the custom image from the Docker Registry server, with the command :

# docker pull 198.167.141.168:5000/alpine:latest

You will be getting an error response like this :

Error response from daemon: Get https://198.167.141.168:5000/v2/: http: server gave HTTP response to HTTPS client

That error response is caused by Docker default configuration only allowing pull process using a secure connection (HTTPS). Because the Docker Registry service that setup on the Docker Registry server (VM 198.167.141.168) only uses an HTTP connection, it will make the pull process into that server fail.

So, to do the pull process from the Docker Registry server using an HTTP connection, we have to add the /etc/docker/daemon.json file with content like the below :

{
   "insecure-registries" : ["198.167.141.168:5000"]
}

The IP Address section is from the IP Address of the Docker Registry server. Save that file, and then restart the Docker service with the command :

# systemctl restart docker.service

After that, try the pull process from the Docker Registry server once again. Since the Docker Registry server IP Address is added into /etc/docker/daemon.json to use the pull process using an HTTP connection, the result will be succeeded like below :

REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
198.167.141.168:5000/alpine   latest    389fef711851   10 days ago     5.58MB

As we can see, the Alpine custom Docker Images are displayed on the docker images list on VM Client (VM 202.43.249.219), indicating the custom image is successfully pulled from our Docker Registry server.

In the future, this Docker Registry server can store and deliver another custom Docker image for multiple application development.

Congratulations! You have configured your own Docker Hub (Docker Registry) on ServerStadium Virtual Machine.

Conclusion

In this guideline, we have installed and configured our own Docker Hub (Docker Registry) on the Virtual Machine ServerStadium environment for serving custom images and containers using Docker Registry as storage and delivering tools to provide custom containers in the application development.

Table of Contents