How To Set up a Docker Registry on Debian 12
Overview
This document outlines how to setup and install a docker registry running in docker-compose.
Set up Docker Registry
Dependencies
We will need grab the authentication tools and a place to put the docker registry in the system, in a standardized place.
sudo apt install apache2-utils -y
sudo mkdir -p /srv/docker/registry
sudo chown -R blair: /srv/docker/registry
cd /srv/docker/regisrySetting up Docker-Compose
We will create a new docker-compose.yaml file:
version: "3"
services:
registry:
image: registry:2
container_name: registry
environment:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry
REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
volumes:
- ./auth:/auth
- container_data:/data
labels:
- "traefik.docker.network=traefik_frontend"
- "traefik.http.routers.registry.rule=Host(`registry.weepynet.com`)"
- "traefik.http.routers.registry.tls=true"
restart: always
dns:
- 172.19.0.254
networks:
- traefik_frontend
volumes:
container_data:
driver: local
networks:
traefik_frontend:
external: trueThis will get the container set up with the traefik front end (reverse proxy), set up to use basic auth, and uses a docker volume to store the docker objects, which is a more stable platform for the data than storing it in a local folder.
Setting up the Authentication
We will now create a user for authentication with the repository.
cd auth
htpasswd -Bc registry.password usernameWhere username is your username. Enter the password as prompted.
When creating additional users, do not pass the -c flag. This is used for the first user only.
htpasswd -B registry.password new_usernameTesting installation
We should now be good to go. Start up the registry and test it out.
cd /srv/docker/registry
docker-compose up -dIn a browser, go to https://registry.weepynet.com/v2/, which should prompt you for credentials. Enter the credentials you set earlier and you should be greeted with this output:
{}Using this registry
From a client machine that needs to use this registry, you will need to do a docker-login
docker login -u <username> -p <password> https://registry.weepynet.comAlternatively, you can leave out the -u and -p switches and enter them interactively.