Pour créer et utiliser un dépôt de conteneurs privé, il est possible de mettre en place une registry de conteneurs locale qui permetra d’héberger ses propres images, de les push ou de les pull comme lorsque des dépôts officiels sont utilisés.
Configuration du registry Installer et Lancer un Conteneur Registry , qui utilise l’image registry de Docker Hub pour créer un dépôt privé sur le port 5000 :
# podman run -d -p 5000:5000 --name myregistry docker.io/library/registry:2
Cela crée un dépôt local accessible via http://localhost:5000 .
# wget http://localhost:5000
[...] Connecting to localhost (localhost)|127.0.0.1|:5000... connected. HTTP request sent, awaiting response... 200 OK Length: 0 Saving to: ‘index.html’ index.html [ <=> ] 0 --.-KB/s in 0s 2024-10-28 15:57:03 (0.00 B/s) - ‘index.html’ saved [0/0]
Pour vérifier si le registre est bien actif, curl
permet de lister les images disponibles (le registre sera vide aucune image n’a été poussée) :
# curl -X GET http://localhost:5000/v2/_catalog
Récupérer, Taguer et Pousser une Image Si l’image n’est pas présente, il faudra d’abord la télécharger avec podman pull
:
# podman pull registry.access.redhat.com/ubi9/ubi
Trying to pull registry.access.redhat.com/ubi9/ubi:latest... Getting image source signatures Checking if image destination supports signatures Copying blob a20d5f0bec2b done | Copying config 769453be74 done | Writing manifest to image destination Storing signatures 769453be7412b405fce28b514238fd8946ccb61a9ad26bdd2054900848166b87
Pour taguer une image :
# podman tag ubi9/ubi localhost:5000/ubi9/ubi
Pour pousser une image le dépôt :
# podman push localhost:5000/ubi9/ubi
Vérification du registre :
# curl -X GET http://localhost:5000/v2/_catalog
{"repositories":["ubi9/ubi"]}
Erreur https L’erreur ci-dessous est due au fait que Podman essaie de se connecter à un registre privé sur localhost:5000 via HTTPS, alors qu’il est configuré pour fonctionner en HTTP.
# podman push localhost:5000/ubi9/ubi
Getting image source signatures Checking if image destination supports signatures Error: Can not copy signatures to docker://localhost:5000/ubi9/ubi:latest: pinging container registry localhost:5000: Get "https://localhost:5000/v2/": http: server gave HTTP response to HTTPS client
Corrections d’erreur Registre en mode insecure Pour corriger l’erreur , il faut configurer le registre comme “insecure “ en indiquant à Podman que le registre localhost:5000
est non sécurisé (HTTP) en modifiant le fichier de configuration des registres de Podman :
# vim /etc/containers/registries.conf
[[registry]] location = "localhost:5000" insecure = true
Ensuite, redémmarer le registry :
# podman restart myregistry
Export et réimport d’image S’il n’est toujours pas possible de push l’image, il est possible de l’exporter et de la réimporter :
Exporter l’image :
# podman save -o ubi9.tar registry.access.redhat.com/ubi9/ubi
Réimporter l’image :
# podman load -i ubi9.tar
Taguer l’image et pousser :
# podman tag registry.access.redhat.com/ubi9/ubi localhost:5000/ubi9/ubi
Pousser l’image :
# podman push --disable-content-trust localhost:5000/ubi9/ubi
Connexion et Récupération d’Image Connexion au dépôt (juste pour le login et mdp si jamais définis) :
# podman login localhost:5000
Username: Password: Login Succeeded!
Test de l’accès :
# podman pull localhost:5000/ubi9/ubi
Configuration des DNS pour un Nom Personnalisé Ajouter une entrée dans /etc/hosts
pour simuler registry.my.localhost.org
:
[...] 127.0.0.1 registry.my.localhost.org
Ajouter des dépots Image PHP Configuration Créer un dossier pour l’image PHP :
Créer le Containerfile associé pour l’image PHP :
# vim my-php/Containerfile
FROM docker.io/library/php:latest COPY ./my-php-app /var/www/html WORKDIR /var/www/html CMD ["php" , "-S" , "0.0.0.0:8000" , "-t" , "/var/www/html" ]
Création d’une application Créer un dossier pour l’application PHP :
# mkdir -p my-php/my-php-app
Créer un Fichier PHP de Test :
# vim /my-php/my-php-app/index.php
Ayant le contenu suivant :
<?php echo "Hello, World!"; ?>
Construction de l’image Se positionner dans le dossier :
Construction de l’image :
# podman build -t registry.my.localhost.org/php-dev .
STEP 1/4: FROM docker.io/library/php:latest Trying to pull docker.io/library/php:latest... Getting image source signatures Copying blob 9b17e980700f done | Copying blob 95ab1cc5ca33 done | Copying blob e807ae4973d0 done | Copying blob 78ee5e1490ca done | Copying blob a480a496ba95 done | Copying blob b6bea85ab96c done | Copying blob 78fe13e61b8e done | Copying blob 68b1db259727 done | Copying blob 63206c0aa27d done | Copying config fd5c76ddd8 done | Writing manifest to image destination STEP 2/4: COPY ./my-php-app /var/www/html --> 899b07efd3ab STEP 3/4: WORKDIR /var/www/html --> 48ea17f37867 STEP 4/4: CMD ["php", "-S", "0.0.0.0:8000", "-t", "/var/www/html"] COMMIT registry.my.localhost.org/php-dev --> 028bfdbbeb13 Successfully tagged registry.my.localhost.org/php-dev:latest 028bfdbbeb130387cad355426a4a5e56bf00b49f5c3ccaeccab6117c14de8ed2
Push de l’image :
# podman push registry.my.localhost.org/php-dev
Si erreur rencontrées, de type https:
Getting image source signatures WARN[0000] Failed, retrying in 1s ... (1/3). Error: trying to reuse blob sha256:98b5f35ea9d3eca6ed1881b5fe5d1e02024e1450822879e4c13bb48c9386d0ad at destination: pinging container registry registry.my.localhost.org: Get "https://registry.my.localhost.org/v2/": dial tcp 127.0.0.1:443: connect: connection refused Getting image source signatures
Il est possible d’y remédier :
# podman run -d -p 5000:5000 --name myregistry --replace docker.io/library/registry:2 # podman tag php-dev localhost:5000/php-dev # podman push localhost:5000/php-dev
Vérification :
# curl http://localhost:5000/v2/_catalog
{"repositories":["php-dev"]}
Image MySQL Créer un dossier pour l’image MYSQL :
Créer le Containerfile associé pour l’image MYSQL :
# vim my-mysql/Containerfile
FROM docker.io/library/mysql:latest ENV MYSQL_ROOT_PASSWORD=MyP455 ENV MYSQL_DATABASE=my_db EXPOSE 3306
Construction de l’image :
# podman build -t registry.my.localhost.org/mysql .
STEP 1/4: FROM docker.io/library/mysql:latest Trying to pull docker.io/library/mysql:latest... Getting image source signatures Copying blob eba3c26198b7 done | Copying blob c0880e4b3737 done | Copying blob 97f7c8c33abe done | Copying blob aa23d877fa04 done | Copying blob a143609ddd2d done | Copying blob 78308a3437c4 done | Copying blob 4bab267f9ce1 done | Copying blob e575f6d9b17a done | Copying blob 607f86c00053 done | Copying blob cd68caa5febe done | Copying config be960704df done | Writing manifest to image destination STEP 2/4: ENV MYSQL_ROOT_PASSWORD=MyP455 --> f8d97dcdb635 STEP 3/4: ENV MYSQL_DATABASE=my_db --> 07ea5193b3b7 STEP 4/4: EXPOSE 3306 COMMIT registry.my.localhost.org/mysql --> 4379222d491f Successfully tagged registry.my.localhost.org/mysql:latest 4379222d491fa9e2cbbd110b3aab6af601c87f25de126f281649d1347815853d
Push de l’image :
# podman push registry.my.localhost.org/mysql
Si erreur rencontrées, de type https:
Getting image source signatures WARN[0000] Failed, retrying in 1s ... (1/3). Error: trying to reuse blob sha256:98b5f35ea9d3eca6ed1881b5fe5d1e02024e1450822879e4c13bb48c9386d0ad at destination: pinging container registry registry.my.localhost.org: Get "https://registry.my.localhost.org/v2/": dial tcp 127.0.0.1:443: connect: connection refused Getting image source signatures
Il est possible d’y remédier :
# podman run -d -p 5000:5000 --name myregistry --replace docker.io/library/registry:2 # podman tag my-mysql localhost:5000/my-mysql # podman push localhost:5000/my-mysql
Vérification :
# curl http://localhost:5000/v2/_catalog
{"repositories":["my-mysql","php-dev"]}
Image Python Créer un dossier pour l’image Python :
Créer le Containerfile associé pour l’image Python (et le répertoire /python
à la racine du système):
# vim my-python/Containerfile
FROM docker.io/library/python:latest COPY ./my-python-app /python/app.py WORKDIR /python CMD ["python" , "app.py" ]
Création d’une application Créer un dossier pour l’application Python :
# mkdir -p my-python/my-python-app
Créer un Fichier Python de Test :
# vim my-python/my-python-app/app.py
Ayant le contenu suivant :
print ("Hello from Python!" )
Construction de l’image Se positionner dans le dossier :
Construction de l’image :
# podman build -t registry.my.localhost.org/python-app .
STEP 1/4: FROM docker.io/library/python:latest STEP 2/4: COPY ./my-python-app /python/app.py --> 4ead4a0f76a3 STEP 3/4: WORKDIR /python --> f36e60fc28d4 STEP 4/4: CMD ["python", "app.py"] COMMIT registry.my.localhost.org/pyhton-dev --> df1d47929903 Successfully tagged registry.my.localhost.org/pyhton-dev:latest df1d479299037776d4e8227f9d1e6d1d341cb9f099c4fce9b4e3910b0f92beaa
Push de l’image :
# podman push registry.my.localhost.org/python-dev
Si erreur rencontrées, de type https:
Getting image source signatures WARN[0000] Failed, retrying in 1s ... (1/3). Error: trying to reuse blob sha256:98b5f35ea9d3eca6ed1881b5fe5d1e02024e1450822879e4c13bb48c9386d0ad at destination: pinging container registry registry.my.localhost.org: Get "https://registry.my.localhost.org/v2/": dial tcp 127.0.0.1:443: connect: connection refused Getting image source signatures
Il est possible d’y remédier :
# podman run -d -p 5000:5000 --name myregistry --replace docker.io/library/registry:2 # podman tag python-dev localhost:5000/python-dev # podman push localhost:5000/python-dev
Vérification :
# curl http://localhost:5000/v2/_catalog
{"repositories":["my-mysql","php-dev","python-dev"]}
Utiliser et Exécuter les Conteneurs depuis le Dépôt PHP Exécuter le conteneur PHP :
# podman run -d --name php-server -p 8000:8000 registry.my.localhost.org/php-dev
MySQL Exécuter le conteneur MYSQL :
# podman run -d --name mysql-db -e MYSQL_ROOT_PASSWORD=yourpassword -p 3306:3306 registry.my.localhost.org/mysql
Python Exécuter le conteneur Python :
# podman run -d --name python-app registry.my.localhost.org/python-dev
Documentation Internet