Got myself a mini pc this weekend and installed ubuntu server 24.04. One of the apps that I really wanted to host is a docker registry. This was the first time that I have done this so might as well document the process.

Install Docker

Since the docker registry will run on docker make sure that docker is installed. I know it’s obvious but putting it here just to be sure.

Generate a Self-Signed Certificate

First make a directory for the generated certificates.

mkdir certs

Here’s the actual openssl command. Replace the value of the IP address for -subj and -addtext. In my case that would be 192.168.100.200.

sudo openssl req -newkey rsa:4096 -nodes -sha256 -x509 -days 3650 -keyout certs/selfsigned.key -out certs/selfsigned.crt -subj "/CN=192.168.100.200" -addext "subjectAltName = IP:192.168.100.200"

Make Docker Trust the Certificate

To do this copy the certificate to /etc/docker/certs.d/(IP:PORT) directory. On windows this directory will be C:\Users\(username)\.docker\certs.d\(IP_PORT).

mkdir /etc/docker/certs.d
mkdir /etc/docker/certs.d/192.168.100.200:5000
cp ./certs/selfsigned.crt /etc/docker/certs.d/192.168.100.200:5000/ca.crt

Then restart docker

sudo systemctl restart docker

Create A User and Password for Docker Registry

For this step we need to use htpasswd to create the username and password. On ubuntu, it is in the apache2-utils package.

sudo apt install apache2-utils

then let’s make a directory for the generated users.

mkdir auth

Now to create a user. In this example the username will be testusername and password is testpassword.

htpasswd -Bbn testusername testpassword > auth/htpasswd

Run The Docker Registry

create a docker-compose.yaml file with the following contents.

services:
  registry:
    image: registry
    container_name: registry
    ports:
      - "5000:5000"
    restart: unless-stopped
    volumes:
      - "./registry-data:/var/lib/registry"
      - "./certs:/certs"
      - "./auth:/auth"
    environment:
      - REGISTRY_HTTP_TLS_CERTIFICATE=/certs/selfsigned.crt
      - REGISTRY_HTTP_TLS_KEY=/certs/selfsigned.key
      - REGISTRY_AUTH=htpasswd
      - REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm
      - REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd

Then create and run the docker registry.

docker compose up -d

Now the docker registry should be up and running.

Accessing The Registry

Let’s login first so that we can push and pull to the registry.

docker login 192.168.100.200:5000

To push and pull from the registry

docker pull 192.168.100.200:5000/<image-id>
docker pull 192.168.100.200:5000/<image-id>

Example

# pull hello-world image from dockerhub
docker pull hello-world

# add another tag pointing to our registry
docker tag hello-world 192.168.100.200:5000/hello-world

# push to our registry
docker push 192.168.100.200:5000/hello-world

# pull from our registry
docker pull 192.168.100.200:5000/hello-world

How To See The List Of Images In The Docker Registry

It can be viewed on the browser at https://IP:PORT/v2/_catalog. In my case it would be https://192.168.100.200:5000/v2/_catalog.

All Done!

And that’s it for setting up a docker registry. I thought of documenting the process here so that I would have a reference that I can easily find if ever I needed to setup another one in the future. So hello to the future, I guess?