How to Host Your Own Docker Images Without Docker Hub

Docker Hub works well until it gets in the way. A pull hits a rate limit during a deploy, a build fails at 2 a.m. because the registry is unreachable, or an image holds something you would rather not store on someone else’s servers. When you host your own docker images, you decide where they live, who can pull them, and how fast they move across your own network. This guide covers the practical setup on a VPS: a private registry behind Nginx with TLS and authentication, plus the habits that keep it running cleanly.

Why host your own docker images

The strongest reason is control. Your images sit on a disk you own, behind credentials you set, and pulling them never depends on a third-party service being up. That matters most for internal tools, client projects, and images built from private code. A self-hosted docker registry also removes pull limits from the deploy path, so a fleet of servers can pull the same image at the same time without queuing behind a shared quota. Pulls from a registry in the same data center finish faster than pulls across the public internet, and that shows up on every deploy.

There are trade-offs. You take on the work Docker Hub used to do: disk space, backups, certificate renewals, and access control. A registry with no backups is worse than no registry at all, because a lost disk means rebuilding every image from source. If you only ship one public image now and then, staying on Docker Hub is the simpler choice. But if you deploy from a VPS every day, running a private docker registry is a small setup job that pays for itself quickly. The site already has a walkthrough of running a private Docker registry on your VPS if you want the shortest path to a working instance before reading the details below.

Your options at a glance

Four setups cover almost every small-team need. Pick by how much management you are willing to take on, not by how many features the project page lists.

Option Best for Built-in auth Effort
Official registry image One VPS, a few images, one team Basic auth via htpasswd Low
Harbor Teams that need projects, scanning, and replication Yes, with roles Medium
Nexus Repository Teams already storing other package types Yes, with roles Medium
S3-compatible storage backend Keeping registry data off the app disk Handled by the registry Medium

For most VPS owners, the official registry image is the right start. It is a single container, it stores images on disk or in S3-compatible storage, and it does one job well. Harbor adds a web interface, vulnerability scanning, and image replication between registries, which is genuinely useful once more than one person pushes images. Nexus makes sense if you already use it for other artifacts. Start simple and move up only when a real need appears.

What you need before you start

You need a VPS with Docker and Docker Compose installed, a domain or subdomain pointing at the server, and a firewall that only exposes ports 22, 80, and 443. The registry itself never faces the internet directly; Nginx sits in front of it and handles TLS and authentication headers. Plan disk space with headroom: every image layer is stored once, but tags accumulate fast, and a 20 GB disk fills up sooner than you expect when images are rebuilt daily. If you have not set up Compose yet, read the walkthrough of your first Docker Compose file first, since the registry runs as a Compose service.

Decide on the registry address now. A subdomain like registry.example.com keeps the registry separate from your sites and makes TLS straightforward with a single certificate.

Set up a private docker registry with Docker Compose

Create a directory for the registry and a Compose file inside it. The registry stores its data in a named volume so it survives container restarts and upgrades.

mkdir -p ~/registry/data ~/registry/auth
cd ~/registry

Generate the password file with the official httpd image, which ships the htpasswd tool:

docker run --rm --entrypoint htpasswd httpd:2.4-alpine -Bbn deployer strong-password > auth/htpasswd

Then write docker-compose.yml:

services:
  registry:
    image: registry:2
    restart: unless-stopped
    ports:
      - "127.0.0.1:5000:5000"
    environment:
      REGISTRY_AUTH: htpasswd
      REGISTRY_AUTH_HTPASSWD_REALM: Private Registry
      REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
      REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /var/lib/registry
    volumes:
      - ./data:/var/lib/registry
      - ./auth:/auth
    healthcheck:
      test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:5000/v2/"]
      interval: 30s
      timeout: 5s
      retries: 3

Binding the registry to 127.0.0.1 is deliberate: nothing outside the server can reach port 5000 directly. Start it with docker compose up -d and confirm the catalog endpoint answers through the local port before moving on.

A docker registry without docker hub still speaks the same protocol, so your existing Docker commands work unchanged. The only difference is the address in the image name: registry.example.com/myapp:latest instead of myuser/myapp:latest.

Put Nginx in front with TLS

Nginx terminates TLS, forwards requests to the registry on localhost, and raises the client body limit so large layers upload without a 413 error. A minimal server block looks like this:

server {
    listen 443 ssl;
    server_name registry.example.com;

    ssl_certificate /etc/letsencrypt/live/registry.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/registry.example.com/privkey.pem;

    client_max_body_size 0;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 900;
    }
}

Get the certificate with Certbot before reloading Nginx, and add an HTTP server block that redirects to HTTPS. If you want the full reverse-proxy pattern explained, see the guide to configuring Nginx as a reverse proxy for Docker containers. Test with nginx -t before reloading, then check that curl https://registry.example.com/v2/ returns a 401 challenge.

Push and pull your first image

Log in from any machine that needs access:

docker login registry.example.com

Tag an existing image with the registry address, then push it:

docker tag myapp:latest registry.example.com/myapp:latest
docker push registry.example.com/myapp:latest

On a second server, pull it the same way you would pull from Docker Hub:

docker pull registry.example.com/myapp:latest

Compose files can reference the registry address directly in the image: field, so deploys need no extra steps beyond a docker login on each host. For CI runners, create a separate htpasswd user and store it as a secret in your CI system.

Keep the registry tidy and backed up

Registries grow quietly. Every rebuild pushes new layers, and old tags pile up until the disk runs out. Set a routine: list tags through the registry API, delete tags you no longer deploy, and run the registry garbage collector with the container stopped so it can safely remove unreferenced blobs. The cleanup guide for cleaning up old Docker images and freeing disk space on your VPS covers the same disk-pressure problem on the client side, and the habits transfer directly.

Back up the storage directory, not just the Compose file. The data directory holds every image layer, so a nightly rsync or restic job to another server covers you. If you already keep off-site copies of your other VPS data, add the registry directory to the same job; the walkthrough of setting up an S3-compatible backup for your VPS with Minio is a solid pattern for this. Test a restore at least once by pulling an image from the backup copy. A backup you have never restored is a guess, not a plan.

Watch disk usage with a simple alert. Check df -h weekly or set an alert at 80 percent; a full disk stops pushes mid-deploy.

Common problems and fixes

Most registry trouble falls into a few buckets. A 413 Request Entity Too Large on push means client_max_body_size is still at its default in Nginx; set it to 0 to disable the limit for the registry vhost. An unauthorized: authentication required error after a successful login usually means the htpasswd file was generated with the wrong format or the auth volume is not mounted; regenerate it with the -Bbn flags shown above. If pushes hang, check the registry logs for disk errors before blaming the network, since a full disk is the most common cause of a push that stalls at the same layer every time.

TLS errors on pull are usually a certificate problem: expired, wrong hostname, or untrusted issuer. Use a Let’s Encrypt certificate rather than a self-signed one, because every Docker client on every machine has to trust it.

When Docker Hub still makes sense

Self-hosting is not a verdict on Docker Hub. Public images belong on a public registry where anyone can pull them, and a team that only deploys a handful of containers may find the maintenance cost of a private registry outweighs the benefit. A docker image registry on a VPS earns its keep when images are private, deploys are frequent, or pull reliability directly affects uptime. If those conditions fit, the setup above takes an afternoon and gives you a registry you fully control.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.