A private Docker registry lets you store and distribute container images within your own infrastructure, avoiding Docker Hub rate limits and keeping proprietary images secure. This guide sets up a private Docker registry with TLS and basic authentication on Ubuntu 26.04 LTS.
Tested and valid on:
- Ubuntu 26.04 LTS
Prerequisites
- Ubuntu 26.04 LTS with Docker Engine and Docker Compose installed
- A domain name with SSL certificate (Let’s Encrypt recommended)
- Nginx installed (optional, for reverse proxy)
Step 1 – Create Registry Directories
mkdir -p ~/registry/{data,auth,certs}
Step 2 – Generate Authentication Credentials
docker run --entrypoint htpasswd httpd:2 -Bbn registryuser StrongPass2026! > ~/registry/auth/htpasswd
Step 3 – Obtain SSL Certificate
sudo certbot certonly --standalone -d registry.example.com
sudo cp /etc/letsencrypt/live/registry.example.com/fullchain.pem ~/registry/certs/
sudo cp /etc/letsencrypt/live/registry.example.com/privkey.pem ~/registry/certs/
Step 4 – Create docker-compose.yml
cat > ~/registry/docker-compose.yml << 'EOF'
services:
registry:
image: registry:2
restart: always
ports:
- "5000:5000"
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/fullchain.pem
REGISTRY_HTTP_TLS_KEY: /certs/privkey.pem
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
volumes:
- ./data:/data
- ./auth:/auth
- ./certs:/certs
EOF
Step 5 – Start the Registry
cd ~/registry
docker compose up -d
docker compose ps
Step 6 – Push and Pull Images
docker login registry.example.com:5000
docker tag nginx:alpine registry.example.com:5000/my-nginx:latest
docker push registry.example.com:5000/my-nginx:latest
docker pull registry.example.com:5000/my-nginx:latest
Step 7 – View Registry Contents
curl -u registryuser:StrongPass2026! https://registry.example.com:5000/v2/_catalog
Conclusion
Your private Docker registry is running on Ubuntu 26.04 LTS with TLS encryption and basic authentication. Configure access controls and integrate it with your CI/CD pipelines for automated image builds and deployments.