How to create a local Docker Hub Registry on Photon OS

In this guide I will show you how to create a local Docker Hub type registry on your laptop or in your data center so that you can securely and quickly push and pull images.

DockerRegistryexample

Typically a developer would need to push and pull images to the Docker Hub on the internet. This can be both slow and insecure as your images are exposed to the public.

dockerhubexample

Let’s get started, install the latest version of Photon OS

Downloads and guides available here https://vmware.github.io/photon/

Name your new server registry.domain.com or something easy to identify it on the network.

The Docker registry requires Docker version 1.6 or greater

Login to Photon OS and type Docker -v and press enter, if you are not running 1.6 or greater follow the steps below otherwise skip those and proceed to installing Docker registry.

Upgrading Docker on Photon to install the local registry.

Ensure that your Photon VM has internet access then, login to your Photon OS as root and type rpm –rebuilddb and press enter

rpm --rebuilddb

Now type yum update docker and press enter

yum update docker

Now type y and press enter to install docker

Now type systemctl daemon-reload and press enter

Now type systemctl restart docker and press enter

Now type docker -v and press enter to verify you have the new version loaded

Now we are ready to install the Docker Registry

Type following and press enter:

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

Note: It could take several minutes to download.

Now login to another Photon OS instance that is running Docker 1.6 or higher and stop the Docker Daemon with the following

systemctl stop docker

In this guide I am not using CA signed certificates on the clients to communicate with the registry so we need to start the docker daemon in insecure mode so it can talk to the registry we created.

Type the following to start the docker daemon in inscure mode

docker -d --insecure-registry registry.corp.local:5000 &

Note: the server name in red will need to change to whatever FQDN or IP address you assigned to your registry server we created earlier.

 

Now let’s test the local registry. Lets pull an image down from the public Docker Hub

Type: docker pull vmwarecna/nginx and press enter

Note : It may take several minutes depending on your internet connection. Later we will show how this is much faster when your working with a local registry.

Now lets tag the image we just downloaded

Type the following and press enter

docker tag vmware/nginx registry.corp.local:5000/myfirstimage

Now lets push the image to the local registry we created earlier

Type:

docker push registry.corp.local:5000/myfirstimage

Now, just to show there are no smoke and mirrors, spin up a new Photon OS and again stop the docker service

Now start the registry in insecure mode

Type:

docker -d --insecure-registry registry.corp.local:5000 &

Now lets pull and run the image from your local registry

Type the following and press enter:

docker run -d -p 80:80 registry.corp.local:5000/myfirstimage

Notice it is much faster as the registry is running locally.

Open a web browser to the IP address of the Photon VM you just ran the container on

You did it!!

Enjoy the power and speed of Photon OS and a local Docker registry!

Remember sharing is caring!

One Reply to “How to create a local Docker Hub Registry on Photon OS”

Leave a Reply

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

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.