Ciao a tutti!
In questa guida vedremo come avviare un docker registry privato.
Il luogo perfetto dove salvare tutte le immagini di progetti che non si vogliono rendere pubblici su hub.docker.com.
Partiamo da questo progetto che ho caricato su github: https://github.com/nutellinoit/docker-registry-letsencrypt
Ho utilizzato 3 container:
- Un container ufficiale docker per avviare il registry, versione 2.6.2.
- Un container che avvia let's encrypt e crea automaticamente il certificato https del nostro registro.
- Un container che espone un navigatore web usando il progetto di https://hub.docker.com/r/hyper/docker-registry-web/
La struttura del progetto è scritta tutta all'interno del docker-compose.yml che contiene l'infrastruttura docker per l'avvio della soluzione.
version: '2'
services:
registry:
restart: always
image: registry:2.6.2
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/live/${REGISTRY_DOMAIN}/fullchain.pem
REGISTRY_HTTP_TLS_KEY: /certs/live/${REGISTRY_DOMAIN}/privkey.pem
volumes:
- ${REGISTRY_DATA}:/var/lib/registry
- ${LETSENCRYPT_PATH}/:/certs
networks:
- registry-net
lets-nginx:
build: ./lets-nginx/
restart: always
volumes:
- ${LETSENCRYPT_CACHE}:/cache
- ${LETSENCRYPT_PATH}:/etc/letsencrypt
- ${HTACCESS_REGISTRY}:/etc/nginx/password_registry
links:
- registry
environment:
EMAIL: ${REGISTRY_EMAIL}
DOMAIN: ${REGISTRY_DOMAIN}
UPSTREAM: registry:5000
ports:
- ${HTTP_PORT}:80
- ${HTTPS_PORT}:443
networks:
- registry-net
registry-web:
image: hyper/docker-registry-web:v0.1.2
ports:
- ${REGWEB_HTTP_PORT}:8080
volumes:
- ${REGWEB_CONF}/registry-web:/conf:ro
- ${REGWEB_DB}:/data
depends_on:
- registry
networks:
- registry-net
networks:
registry-net:
Come potete vedere, è tutto gestito dalle variabili d'ambiente, per rendere il più possibile customizzabile l'avvio di questo registry.
Tutto quello che si dovrà fare sarà copiare i due file di esempio (.env.example
e password_registry_example
) nella loro controparte sotto .gitignore
cp .env.example .env
cp password_registry_example password_registry
A questo punto possiamo modificare sia il password_registry
sia il .env
. Il file della password si può modificare facilmente usando http://www.htaccesstools.com/htpasswd-generator/
Per il file .env
vediamo la struttura:
# Let's encrypt data path
# folders
LETSENCRYPT_CACHE=./cache
LETSENCRYPT_PATH=./letsencrypt
# file
HTACCESS_REGISTRY=./password_registry
# Ports
HTTP_PORT=80
HTTPS_PORT=443
# Registry data path
# folders
REGISTRY_DATA=./datalocal
# config
REGISTRY_DOMAIN=registry.domain.tld
REGISTRY_EMAIL=demo@domain.tld
# Registry web browser data path
# folders
REGWEB_CONF=./conf
REGWEB_DB=./db
# Ports
REGWEB_HTTP_PORT=8080
Si può lasciare tutto invariato tranne due parametri:
REGISTRY_DOMAIN
che conterrà il nostro nome dominio del registroREGISTRY_EMAIL
che conterrà l'indirizzo email del nostro gestore del dominio
Una volta fatte queste personalizzazioni possiamo tranquillamente avviare tutto con
docker-compose up -d
Dato che l'emissione del certificato occuperà un pò di tempo, dovremo probabilmente stoppare e riavviare un paio di volte la soluzione. Alla fine avremo però il nostro registro avviato e funzionante!
Ecco un piccolo video dell'avvio e login all'interno di un registro di test: