Running a private registry
Self-hosting images with the registry:3 image or Harbor: TLS, htpasswd auth, deleting and garbage-collecting, pull-through caching, and when not to bother.
Running a private registry
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- The reference open-source registry is CNCF Distribution, which began as Docker's registry and defined the v2 API. Its image is registry:3, which stores blobs and manifests on disk or in object storage and serves the OCI distribution API on port 5000.
- Version 3 reads its config from /etc/distribution/config.yml, and any setting can be overridden with a REGISTRY_ environment variable, where each underscore marks one level of the YAML.
- Docker refuses plain HTTP for registries other than loopback addresses unless you list them as insecure. Use TLS, with a public certificate or your CA in /etc/docker/certs.d/<host:port>/ca.crt.
- Built-in auth is htpasswd with bcrypt only, and it needs TLS. For teams, a token server or a registry with real accounts, such as Harbor, is the next step.
- Deleting an image only removes references. Disk space comes back when you run garbage-collect, a stop-the-world job with the registry read-only or stopped.
- In proxy mode the same image becomes a pull-through cache for Docker Hub, which saves bandwidth and rate limit but can't accept pushes.
Why host your own
Most teams should use a hosted registry: GHCR, ECR or Artifact Registry, as in Docker Hub and other registries. Running your own makes sense when images must not leave the building (air-gapped and regulated networks), when a site has poor internet and needs a local cache, when you want to stop spending Docker Hub pulls on every CI job, or when the bill for a hosted registry outgrows a small server and some disks. The cost is that you now operate a critical service: if the registry is down, nothing deploys.
The registry image
The reference implementation is CNCF Distribution, which began as Docker’s own registry and defined the v2 API that became the OCI distribution spec. It’s now at version 3.1.2. Its Docker Official Image is registry. I checked the tags: registry:latest, registry:3 and registry:3.1.2 share one digest, and registry:2 is a different, older image. Its config says how it runs:
Entrypoint: ["/entrypoint.sh"]
Cmd: ["/etc/distribution/config.yml"]
ExposedPorts: 5000/tcp
Volumes: /var/lib/registry
Version 3 moved the config file from /etc/docker/registry/config.yml, which many older guides still mount, to /etc/distribution/config.yml. The smallest useful run, from the Distribution deploy guide:
docker run -d -p 5000:5000 --restart=always --name registry \
-v registry-data:/var/lib/registry registry:3
docker tag alpine:3.24 localhost:5000/alpine:3.24
docker push localhost:5000/alpine:3.24
Blobs land under /var/lib/registry, so put that on a volume or a real disk. For more than one server, switch the storage driver to S3, GCS or Azure Blob and run several registry containers behind a load balancer.
Configuration through the environment
Every config key can be overridden by an environment variable named REGISTRY_ plus the YAML path, with underscores marking levels. So storage.filesystem.rootdirectory becomes REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY. Here is a Compose service for a registry with TLS, basic auth and deletion enabled. I wrote it from the deploy guide and parsed it with Python’s yaml to check each variable maps to the key I meant:
services:
registry:
image: registry:3.1.2
restart: unless-stopped
ports:
- "443:5000"
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/registry.example.com.crt
REGISTRY_HTTP_TLS_KEY: /certs/registry.example.com.key
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: "Registry Realm"
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_STORAGE_DELETE_ENABLED: "true"
volumes:
- registry-data:/var/lib/registry
- ./certs:/certs:ro
- ./auth:/auth:ro
volumes:
registry-data:
REGISTRY_HTTP_TLS_CERTIFICATE -> http.tls.certificate
REGISTRY_AUTH_HTPASSWD_PATH -> auth.htpasswd.path
REGISTRY_STORAGE_DELETE_ENABLED -> storage.delete.enabled
TLS and trust
Docker talks HTTPS to registries. Plain HTTP is allowed only for loopback addresses (localhost, 127.0.0.0/8, ::1) and for hosts you list under insecure-registries in daemon.json. Everything else fails with “server gave HTTP response to HTTPS client”. Engine 29.10 changed one detail: if you set insecure-registries yourself, loopback is no longer added automatically, so localhost:5000 has to be listed too.
For production, give the registry a certificate. A public one, for example from Let’s Encrypt (the registry can fetch one itself through its letsencrypt settings), needs nothing on the clients. With an internal CA, each Docker host needs the CA at /etc/docker/certs.d/registry.example.com:443/ca.crt. Rootless Docker and Docker Desktop use their own certs.d locations.
Authentication
The built-in options are thin. htpasswd gives basic auth, and the deploy guide warns of two traps: only bcrypt hashes work, so generate them with htpasswd -B, and it only works over TLS. Every user can push and pull everything. For real access control, the registry supports delegating to a token server, but most teams that need users, projects and permissions run Harbor instead. Harbor is a CNCF graduated project, now at 2.15, built around Distribution and adding a UI, RBAC, vulnerability scanning, replication, quotas and a proxy cache. Zot, Nexus and Artifactory are other choices, and GitLab and Gitea ship registries with their forges.
Deleting and garbage collection
Deletion is off by default (storage.delete.enabled: false). When it’s on, you delete a manifest by digest through the API, DELETE /v2/<name>/manifests/<digest>. That frees nothing yet. Layers can be shared between images, so the registry can’t safely delete a blob when one manifest goes. Space comes back from a separate mark-and-sweep:
docker exec registry registry garbage-collect --dry-run /etc/distribution/config.yml
docker exec registry registry garbage-collect --delete-untagged /etc/distribution/config.yml
The Distribution docs call it stop-the-world garbage collection: the registry should be read-only (maintenance.readonly) or stopped while it runs, or an upload in progress can lose a blob. Schedule it for quiet hours. --delete-untagged also removes manifests no tag points at.
A pull-through cache
Add a proxy section with remoteurl: https://registry-1.docker.io (and optionally Docker Hub credentials and a ttl, 168 h by default) and the registry becomes a cache. The first pull fetches from Docker Hub and stores it, and later pulls are served locally. Point Docker at it with "registry-mirrors": ["https://mirror.company.example"] in daemon.json. The mirror docs list the limits: Docker’s registry-mirrors setting only mirrors Docker Hub, a mirror URL must be a bare host with no path, one registry proxies one upstream, and a proxy-mode registry doesn’t accept pushes. Run it beside, not instead of, your private registry.
About the video
The embed is all of package main’s “Self-Hosting a Container Registry”, September 2024, 20 minutes. Its chapters cover container image basics, understanding registries, a self-hosting strategy, setting up the registry, configuring nginx and SSL, pushing images and testing, and advanced tools, with Harbor and a registry web UI linked in the description. It predates Distribution 3’s config path and Engine 29.10’s insecure-registry change, and it doesn’t cover garbage collection or proxy mode, which the lesson adds. English was judged from the channel and its English caption track. Engineering with Morris in deeper installs Harbor.
What was run: the registry tags and the registry:3 image config were read from Docker Hub’s registry API, and the Compose file was parsed with Python’s yaml and its variables mapped to config paths by the documented rule. No registry was started, since there is no Docker here. The configuration, TLS, auth, garbage-collection and mirror details are from the Distribution docs, Docker’s certificate docs and the Engine 29.10 release notes, checked 2026-11-28.
Where this fits
That ends images and registries. Next, writing your own images: Dockerfile instructions from FROM to CMD.
Check yourself
docker push registry.internal:5000/api fails with 'http: server gave HTTP response to HTTPS client'. What are the two fixes, and which is right for production?
Serve TLS on the registry, or add registry.internal:5000 to insecure-registries in daemon.json. TLS is the production answer, because the insecure setting turns off transport protection for that host.
You deleted 200 old tags from your registry through the API, but the disk is no larger. Why?
Deletion removes manifest references. Blobs stay until registry garbage-collect runs a mark-and-sweep, which should happen with the registry stopped or read-only.
After upgrading Docker Engine to 29.10, pushes to localhost:5000 suddenly fail. What changed?
If daemon.json sets insecure-registries explicitly, Engine 29.10 no longer adds loopback addresses to it automatically. Add localhost:5000 to the list or give the registry a trusted certificate.
When is Harbor worth running instead of the plain registry image?
When you need users and projects with role-based access, a web UI, vulnerability scanning, replication between sites, signature policies or quotas. The plain registry only stores and serves images.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.