Create Docker Private Registry

I have used Docker compose to create a private registry that is used to store my docker images. I then run the containers on the same server as the registry. The images are uploaded from my Mac.

I haven’t used Docker a lot so, several guides were required for me to get this to work. Digital Ocean has many excellent articles for Docker and Nginx. I am not going to try to recreate those, just reference them in terms of what I did, so I can remember what went wrong.
This process took a lot longer than anticipated after a few methods turned to dead ends.

There are several steps to getting a private repository installed and working. The main guide I used is from Digital Ocean, it goes through the prerequisites of installing; Docker, Docker compose and Nginx.
Install Docker
Install Docker Compose
Install Nginx
Configure Docker Registry
Configure Nginx Port Forwarding
Configure SSL Authentication
Configure Docker Registry as a Service
Increasing File Upload Size for Nginx
Publishing to Your Private Docker Registry
Pulling From Your Private Docker Registry
Configure Nginx Port Forwarding for Finance Calculator

For all of this, I have used the following versions;
Ubuntu 20.04.5 LTS
Docker version 20.10.22, build 3a2c30b
Docker-compose version 1.29.2, build 5becea4c

Installing Docker

I had already installed Docker on my Ububntu VM prior to this, so I did not need this guide. However, I did run into an issue with the docker username not being added to my groups. The Digital Ocean guide includes this, so probably best to do it. It also means that you don’t need to use sudo for each docker command.
My fix was to follow this guide.

The only thing to add to this is that adding a new user group should require a restart on a VM. This may be sidestepped with running the command newgrp , as described in the Docker documentation.

Install Docker Compose

The next part is to install Docker compose. This was quite straight forward. I used the exact same version as in the guide.

Install Nginx

Nginx install, again pretty straightforward for anyone familiar with Linux. The only issue I did encounter was that my “server blocks” (vhosts in Apache) did not work. I did add the default domian.conf file and this seemed to resolve my issue.

Docker Registry Configuration

This next section covers the configuration of the Docker registry. There were a number of issues with this configuration that mainly revolved around the SSL certificate. First, the SSL must now have a SAN in it. Second, the SSL certificate being self-signed must be added to the CA stores of all devices connecting. Docker is quite strict about this, and I was not able to find a way to ignore untrusted certificates as can be easily done for a REST API.

Configure Docker Registry

This is step 1 of the guide. Some useful commands to use to check everything is running…

Configure Nginx Port Forwarding

This is the part that allows the access from outside the Ubuntu server to the Docker container. Without this port forwarding, the container would only be accessible locally from the Ubuntu server.

I needed to do a few things here after following the Digital Ocean guide. First, I got an error for permissions.

This was fixed with following this guide and adding in the docker group. I added the group and user with the following commands.

Configure SSL Authentication

There were no issues with this section. The problems I faced were when attempting to login to the Docker registry, I received an error about the use of the common name field being legacy.

The solution to this was to create a new self-signed cert and key to replace the old one. I chose to use the exact same names, so I would not need to modify any Nginx config.

This did however bring about another problem about the SSL not being from a trusted CA, but the fix was to just restart the docker service.

Configure Docker Registry as a Service

Nice and easy to problems here

Increasing File Upload Size for Nginx

Also, no issues with this, only basic setting changed to allow a file of upto 16 GB uploaded to the Nginx server.

Publishing to Your Private Docker Registry

Docker images can now be pushed into the registry once logged in. The registry can also be connected to over browser. It’s not a real web page, just a JSON response that a browser can display. To my understanding, there isn’t a way to view the images on a remote registry. So the browser is a handy little feature that will do for testing.

Now this is simple to do on the same Ubuntu machine as the private registry is stored, however a little more difficult on another machine as that must also trust the self-signed cert. I have used my Mac for this and copied the cert from the Ubuntu server and placed it into my system as a root cert. After a reboot, I was able to successfully login and upload images to the private registry.

Pulling From Your Private Docker Registry

The pulling of the images in my scenario is on the Ubuntu server. The server that stores the images will also run the containers.

Configure Nginx Port Forwarding for Finance Calculator

This is the last part of the puzzle, which is basically a repeat of the method of Nginx port forwarding for the registry.

First I copied the working registry server block, and modified it to be HTTP only and run specifically on IP 172.17.0.2 on port 5000.

Next I copied the default Nginx site to the new domains .conf file as I had done for the registry and created the symlink for sites-enabled.

Test Nginx, restart and done!

Run the new container

Running to see the console output
MMC.house as DNS name

Leave a Comment

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