Home / Technology / Local Docker Registry Setup Guide

Local Docker Registry Setup Guide

Prerequisites

  • Make sure your machine has public IP associate with itself
  • Ensure you have sudo privileges on your system.
  • Update your system’s package list and upgrade existing packages.

Step 1: Install Docker and Docker Compose

  1. Update Your System:
   sudo apt update && sudo apt upgrade -y
  1. Install Docker:
   sudo apt install -y docker.io
   sudo systemctl enable --now docker
  1. Add User to Docker Group:
   sudo usermod -aG docker $USER
   newgrp docker
  1. Verify Docker Installation:
   docker --version

Step 2: Run a Local Docker Registry

  1. Run the Registry:
   docker run -d -p 5000:5000 --name registry --restart always registry:2
  1. Verify the Registry is Running:
   curl http://localhost:5000/v2/
  1. Check Available Registry Images:
   curl http://localhost:5000/v2/_catalog

Step 3: Secure the Registry with Authentication

  1. Create Authentication Credentials:
   sudo mkdir -p /etc/docker/registry
   sudo chmod 777 /etc/docker/registry
  1. Install Apache Utilities (htpasswd):
   sudo apt update
   sudo apt install -y apache2-utils
  1. Generate Credentials:
   htpasswd -Bbn   > /etc/docker/registry/htpasswd
  1. Login to the Private Registry:
   docker login localhost:5000

Step 4: Secure the Registry with SSL/TLS

  1. Install Certbot for SSL Certificates:
   sudo apt install -y certbot
  1. Generate an SSL Certificate:
   sudo certbot certonly --standalone -d-
  1. Run the Registry with SSL & Authentication:

At First Stop the running registry

   docker stop registry && docker rm registry

Then run the registry again with

   docker run -d -p 5000:5000 --name registry --restart always 
   -v /etc/docker/registry:/auth 
   -v /etc/letsencrypt:/certs 
   -e "REGISTRY_AUTH=htpasswd" 
   -e "REGISTRY_AUTH_HTPASSWD_REALM=" 
   -e "REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd" 
   -e "REGISTRY_HTTP_TLS_CERTIFICATE=/certs/live//fullchain.pem" 
   -e "REGISTRY_HTTP_TLS_KEY=/certs/live//privkey.pem" 
   registry:2
  1. Test Secure Connection:
   curl -k -u :'' https://:5000/v2/

Troubleshooting

If you encounter any issues, run the following commands to adjust permissions:

sudo chmod -R 755 /etc/letsencrypt/
sudo chmod -R 755 /etc/letsencrypt/live/
sudo chmod -R 644 /etc/letsencrypt/live//*
sudo chmod -R 644 /etc/letsencrypt/archive//*
sudo chmod 640 /etc/docker/registry/htpasswd
sudo chown root:docker /etc/docker/registry/htpasswd