Running a local container registry
In the spirit of learning new things, I figured it’d be nice to have a local container registry for personal projects so I don’t have to fuss with Docker Hub or other. It also pairs nicely with the bare-metal Kubernetes cluster I’m building. Let’s set one up!
I originally learned how to create a local registry from FreeCodeCamp’s great How to Self-host a Container Registry article. I’m sharing my setup here because it differs slightly:
- I use Caddy instead of nginx
- I use a self-signed cert instead of Let’s Encrypt … my server isn’t accessible from the internet
- I wanted to run the registry as an unprivileged user within Docker
- I wanted my registry to be available at
registry.home.arpawithin my network
Network preparation
Before changing my server configuration, I first needed to configure my home network to recognize registry.home.arpa. So I edited my dnsmasq configuration file and added a static DNS record for registry.home.arpa pointing to my server’s IP address.
Server configuration
My main home server is a Debian machine that already runs docker. And thankfully, Docker (the company) publishes a registry container for running your own local container registry. Geez that’s a mouthful …
First, I created a standalone user and group.
|
|
Then, as the new registry user, I created some necessary directories.
|
|
I used the following Docker Compose YAML, with the user parameter, and numeric user+group ids, so it runs unprivileged.
|
|
I’m using htpasswd as the REGISTRY_AUTH option, so I used the following command to create the password file.
|
|
Then, I generated a self-signed TLS certificate.
|
|
Next, I copied the certs to a location accessible by Caddy, and updated my Caddyfile with the following site configuration. I use Caddy as a webserver whenever I can.
|
|
After that, I copied the registry.home.arpa.crt file to every Debian server that will be talking to the registry. Then I moved the file into the right folder and ran a command to have Linux recognize it.
|
|
On my docker machine, I ran systemctl restart docker to pick up the new self-signed cert.
With the cert in place, I once again changed to my registry user and started the registry.
|
|
Finally, I restarted Caddy to enable the new site.
Kick the tires
You should hopefully have a working registry now. Try logging in as a test.
|
|
If that works, you should be all set. Push, pull, be happy.