Self-hosted Docker registry with automated build services.
Warning
Automated builds: build.json
The legacy build list from the URL above is being deprecated due to the new method of hosting images through the GitHub Container Registry.
Our GitHub Container Registry package list can be seen here:
docker run --detach --publish 5000:5000 --restart=unless-stopped --name registry --volume registry:/var/lib/registry registry:2.7.1
Clone this repository in /opt
and enter the directory.
cd /opt
git clone [email protected]:01-edu/registry.git
cd /opt/registry
Install Caddy, add the Caddyfile to /etc/caddy/Caddyfile
and reload it:
systemctl reload caddy
First time only (to allow the service to push to the Docker registry) :
docker login docker.01-edu.org
go build
./registry -port 8081 2>log.txt &
Check that the images are correctly built:
tail -f log.txt
After a moment, you should see some messages similar to this:
2021/04/08 16:20:01 docker [pull alpine:3.13.2]
2021/04/08 16:20:03 docker [tag alpine:3.13.2 docker.01-edu.org/alpine:3.13.2]
2021/04/08 16:20:03 docker [push docker.01-edu.org/alpine:3.13.2]
To make it start with the system, edit cron jobs:
crontab -e
Add this line:
@reboot /usr/bin/env bash -l sleep 10; /opt/registry/restartRegistry.sh
Save & exit.
To pull from this registry, you need to log in first (with the password defined in Caddyfile):
docker login docker.01-edu.org
To check if the service is working correctly, check the logs.
- To build from a Git repository: edit build.json.
- To mirror an already existing image: edit mirror.json.
- To make a
PUT
HTTP request to webhooks: edit webhooks.json.
If you edit those files directly on GitHub or push them, the service will pull the new changes and take them into account.
Manually trigger a rebuild (because the webhook wasn't configured correctly); here is an example with github.com/01-edu/public:
curl https://webhook.docker.01-edu.org -d'{"ref":"refs/heads/master","repository":{"ssh_url":"[email protected]:01-edu/public.git"}}'
To remove dangling images in the registry:
docker exec registry bin/registry garbage-collect /etc/docker/registry/config.yml --delete-untagged=true
To relaunch the registry service, you can run the restartRegistry.sh
script.
cd /opt/registry
./restartRegistry.sh
- Docker Hub is taking a very long time to build (up to half an hour)
- Now rate limits the pulls
- Is quite easy to re-implement
Deploying a web server, a registry (as a Docker container), and an automated build service on a dedicated server guarantees unlimited pulls & fast builds.
Following the official guide but using Caddy to handle HTTPS (because it's easier), authentication (because it's easier) and proxy to the service.