Your own image registry
When you need your own registry, how to set it up with a password and certificate, how much disk it consumes, and how not to turn it into a dump of old images.
Updated August 23, 2026
A registry is a store of images. You need your own in three cases: the images are private and must not leave your infrastructure, builds happen often and external download limits get in the way, or you deploy the same thing across several machines.
Simple option: registry:2
services:
registry:
image: registry:2
restart: unless-stopped
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
REGISTRY_STORAGE_DELETE_ENABLED: "true"
volumes:
- ./data:/var/lib/registry
- ./auth:/auth:ro
ports:
- "127.0.0.1:5000:5000"
Create the password like this:
mkdir -p auth
docker run --rm --entrypoint htpasswd httpd:2 -Bbn deploy 'long-password' > auth/htpasswd
docker compose up -d
Don't expose the port externally: a web server with a certificate goes in front of the registry. Docker refuses to work with a third-party registry over HTTP — and rightly so, because executable code arrives on your machines through it.
Working with it
docker login registry.example.com
docker tag myapp:1.5.0 registry.example.com/myapp:1.5.0
docker push registry.example.com/myapp:1.5.0
docker pull registry.example.com/myapp:1.5.0
curl -u deploy https://registry.example.com/v2/_catalog
curl -u deploy https://registry.example.com/v2/myapp/tags/list
After docker login, the credentials sit in ~/.docker/config.json in plain text (base64 is not encryption). On build machines, create a separate account with read-only rights.
A registry with no size limit and no cleanup is the fastest way to fill up a disk. Every build adds layers, and deleting a tag doesn't free space: you need garbage collection. On VDS-1 with 40 GB, an active project's registry will fill the disk in a couple of weeks.
Cleanup
Deleting a tag and the subsequent garbage collection:
docker compose exec registry registry garbage-collect \
--delete-untagged /etc/docker/registry/config.yml
You must stop the registry while garbage collection runs — otherwise a concurrent push can lose layers:
docker compose stop registry
docker compose run --rm registry registry garbage-collect --delete-untagged /etc/docker/registry/config.yml
docker compose start registry
Set this up as a scheduled job once a week and keep an eye on disk space.
Alternative: a registry bundled with a Git server
If you've already set up Forgejo or Gitea, they have a built-in package store, including Docker images. You don't need a separate service: access goes through the same accounts, and the images are visible next to the code. For small projects this is more convenient than a standalone registry:2.
Common mistakes
- The registry is open without authorization. Through it, someone can plant an image that will be deployed on your own production machine.
- The
latesttag instead of versions. The registry stops being a source of reproducibility: it's unclear what exactly is deployed. See updating containers. - Storage on the same disk as the database. A spike in pushes eats up disk bandwidth and slows down the production service — see disk speed.
- The
./datadirectory isn't in your backups. You'll lose all images for which you don't have the sources at hand. See what to back up.