Registre des hôtes
Registry est un registre Docker auto-hébergé qui vous permet de stocker et de gérer vos images Docker. Il est similaire à Docker Hub, mais il est auto-hébergé et peut être utilisé pour des dépôts privés.
Pour héberger Registry sur AnduinOS, exécutez les commandes suivantes.
Tout d'abord, assurez-vous que Docker est installé sur votre machine. Sinon, vous pouvez installer Docker en exécutant les commandes suivantes :
sudo apt install -y docker.io
Créez un nouveau dossier pour enregistrer les fichiers de configuration du service :
# Please install Docker first
mkdir -p ~/Source/ServiceConfigs/Registry
cd ~/Source/ServiceConfigs/Registry
Assurez-vous qu'aucun autre processus n'utilise le port 6157 sur votre machine.
function port_exist_check() {
if [[ 0 -eq $(sudo lsof -i:"$1" | grep -i -c "listen") ]]; then
echo "$1 is not in use"
sleep 1
else
echo "Warning: $1 is occupied"
sudo lsof -i:"$1"
echo "Will kill the occupied process in 5s"
sleep 5
sudo lsof -i:"$1" | awk '{print $2}' | grep -v "PID" | sudo xargs kill -9
echo "Killed the occupied process"
sleep 1
fi
}
port_exist_check 8080
Ensuite, créez un fichier docker-compose.yml avec le contenu suivant :
cat << EOF > ./docker-compose.yml
version: '3.9'
services:
registry-ui:
depends_on:
- registry-server
image: joxit/docker-registry-ui:main
ports:
- target: 80
published: 8080
protocol: tcp
mode: host
networks:
- net
environment:
- SINGLE_REGISTRY=true
- REGISTRY_TITLE=My Registry
- DELETE_IMAGES=true
- SHOW_CONTENT_DIGEST=true
- NGINX_PROXY_PASS_URL=http://registry-server:5000
- SHOW_CATALOG_NB_TAGS=true
- CATALOG_MIN_BRANCHES=1
- CATALOG_MAX_BRANCHES=1
- TAGLIST_PAGE_SIZE=100
- REGISTRY_SECURED=false
- CATALOG_ELEMENTS_LIMIT=1000
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
update_config:
order: start-first
registry-server:
image: registry
volumes:
- registry-data:/var/lib/registry
networks:
- net
environment:
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Origin: '[https://hub.aiursoft.com]' # Replace with your domain
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Methods: '[HEAD,GET,OPTIONS,DELETE]'
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Credentials: '[true]'
REGISTRY_HTTP_HEADERS_Access-Control-Allow-Headers: '[Authorization,Accept,Cache-Control]'
REGISTRY_HTTP_HEADERS_Access-Control-Expose-Headers: '[Docker-Content-Digest]'
REGISTRY_STORAGE_DELETE_ENABLED: 'true'
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
update_config:
order: start-first
registry-cleaner:
depends_on:
- registry-server
image: alpine:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
entrypoint:
- "/bin/sh"
- "-c"
- |
echo "Installing docker";
apk add --no-cache docker;
echo "Starting registry cleaner";
sleep 20;
docker ps --filter name=registry-server -q | xargs -r -I {} docker exec {} registry garbage-collect /etc/docker/registry/config.yml --delete-untagged=true;
echo "Garbage collection done. Sleeping infinitely.";
sleep infinity;
deploy:
resources:
limits:
cpus: '1.0'
memory: 1G
update_config:
order: start-first
volumes:
registry-data:
driver: local
driver_opts:
type: none
o: bind
device: /swarm-vol/registry-data
networks:
net:
driver: overlay
EOF
sudo mkdir -p /swarm-vol/registry-data
Ensuite, déployez le service :
sudo docker swarm init --advertise-addr $(hostname -I | awk '{print $1}')
sudo docker stack deploy -c docker-compose.yml registry --detach
C'est tout ! Vous avez hébergé avec succès le registre sur AnduinOS.
Vous pouvez accéder au registre en visitant http://localhost:8080 dans votre navigateur.
Désinstallation
Pour désinstaller Registry, exécutez les commandes suivantes :
sudo docker stack rm registry
sleep 20 # Wait for the stack to be removed
sudo docker system prune -a --volumes -f # Clean up used volumes and images
Pour supprimer également les fichiers de données, journaux et configuration, exécutez les commandes suivantes :
sudo rm /swarm-vol/registry-data -rf
C'est tout ! Vous avez désinstallé avec succès Registry d'AnduinOS.
Commentaires (0)
Aucun commentaire pour le moment. Soyez le premier à en laisser un !