Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
elearning:workbooks:docker3:drf02 [2023/12/27 07:50] – removed admin | elearning:workbooks:docker3:drf02 [2024/02/21 13:41] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ~~PDF: | ||
+ | Version : **2024.01** | ||
+ | |||
+ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
+ | |||
+ | ======DOF603 - Gérer et Stocker les Images Docker====== | ||
+ | |||
+ | =====Contenu du Module===== | ||
+ | |||
+ | * **DOF603 - Gérer et Stocker les Images Docker** | ||
+ | * Contenu du Module | ||
+ | * LAB #1 - Re-créer une image officielle docker | ||
+ | * 1.1 - Utilisation d'un Dockerfile | ||
+ | * 1.2 - FROM | ||
+ | * 1.3 - RUN | ||
+ | * 1.4 - ENV | ||
+ | * 1.5 - VOLUME | ||
+ | * 1.6 - COPY | ||
+ | * 1.7 - ENTRYPOINT | ||
+ | * 1.8 - EXPOSE | ||
+ | * 1.9 - CMD | ||
+ | * 1.10 - Autres Commandes | ||
+ | * LAB #2 - Créer un Dockerfile | ||
+ | * 2.1 - Création et test du script | ||
+ | * 2.2 - Bonnes Pratiques liées au Cache | ||
+ | * LAB #3 - Installer un Registre Privé | ||
+ | * 3.1 - Créer un Registre local, | ||
+ | * 3.2 - Créer un Serveur de Registre Dédié | ||
+ | * Configurer le Client | ||
+ | |||
+ | =====LAB #1 - Re-créer une image officielle docker===== | ||
+ | |||
+ | ====1.1 - Utilisation d'un Dockerfile==== | ||
+ | |||
+ | Bien que la compilation des images soient assuré par Docker Hub, il est tout à fait possible de compiler une image " | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Le Docker file contient les instructions nécessaires pour la contruction de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | FROM ubuntu: | ||
+ | |||
+ | # add our user and group first to make sure their IDs get assigned consistently, | ||
+ | RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | ||
+ | |||
+ | RUN set -eux; \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | ca-certificates \ | ||
+ | jq \ | ||
+ | numactl \ | ||
+ | ; \ | ||
+ | if ! command -v ps > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends procps; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | |||
+ | # grab gosu for easy step-down from root (https:// | ||
+ | ENV GOSU_VERSION 1.11 | ||
+ | # grab " | ||
+ | ENV JSYAML_VERSION 3.13.0 | ||
+ | |||
+ | RUN set -ex; \ | ||
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; | ||
+ | # gpg --batch --verify / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | chmod +x / | ||
+ | gosu --version; \ | ||
+ | gosu nobody true; \ | ||
+ | \ | ||
+ | wget -O /js-yaml.js " | ||
+ | # TODO some sort of download verification here | ||
+ | \ | ||
+ | apt-get purge -y --auto-remove wget | ||
+ | |||
+ | RUN mkdir / | ||
+ | |||
+ | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B | ||
+ | RUN set -ex; \ | ||
+ | export GNUPGHOME=" | ||
+ | for key in $GPG_KEYS; do \ | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys " | ||
+ | done; \ | ||
+ | gpg --batch --export $GPG_KEYS > / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | apt-key list | ||
+ | |||
+ | # Allow build-time overrides (eg. to build image with MongoDB Enterprise version) | ||
+ | # Options for MONGO_PACKAGE: | ||
+ | # Options for MONGO_REPO: repo.mongodb.org OR repo.mongodb.com | ||
+ | # Example: docker build --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com . | ||
+ | ARG MONGO_PACKAGE=mongodb-org-unstable | ||
+ | ARG MONGO_REPO=repo.mongodb.org | ||
+ | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} | ||
+ | |||
+ | ENV MONGO_MAJOR 4.1 | ||
+ | ENV MONGO_VERSION 4.1.9 | ||
+ | # bashbrew-architectures: | ||
+ | RUN echo "deb http:// | ||
+ | |||
+ | RUN set -x \ | ||
+ | && apt-get update \ | ||
+ | && apt-get install -y \ | ||
+ | ${MONGO_PACKAGE}=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ | ||
+ | && rm -rf / | ||
+ | && rm -rf / | ||
+ | && mv / | ||
+ | |||
+ | RUN mkdir -p /data/db / | ||
+ | && chown -R mongodb: | ||
+ | VOLUME /data/db / | ||
+ | |||
+ | COPY docker-entrypoint.sh / | ||
+ | ENTRYPOINT [" | ||
+ | |||
+ | EXPOSE 27017 | ||
+ | CMD [" | ||
+ | </ | ||
+ | |||
+ | Le fichier docker-entrypoint.sh sert à lancer le serveur mongodb dans le conteneur : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | #!/bin/bash | ||
+ | set -Eeuo pipefail | ||
+ | |||
+ | if [ " | ||
+ | set -- mongod " | ||
+ | fi | ||
+ | |||
+ | originalArgOne=" | ||
+ | |||
+ | # allow the container to be started with `--user` | ||
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
+ | |||
+ | # make sure we can write to stdout and stderr as " | ||
+ | # (for our " | ||
+ | chown --dereference mongodb "/ | ||
+ | # ignore errors thanks to https:// | ||
+ | |||
+ | exec gosu mongodb " | ||
+ | fi | ||
+ | |||
+ | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | ||
+ | # https:// | ||
+ | if [[ " | ||
+ | numa=' | ||
+ | if $numa true &> /dev/null; then | ||
+ | set -- $numa " | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # usage: file_env VAR [DEFAULT] | ||
+ | # ie: file_env ' | ||
+ | # (will allow for " | ||
+ | # " | ||
+ | file_env() { | ||
+ | local var=" | ||
+ | local fileVar=" | ||
+ | local def=" | ||
+ | if [ " | ||
+ | echo >&2 " | ||
+ | exit 1 | ||
+ | fi | ||
+ | local val=" | ||
+ | if [ " | ||
+ | val=" | ||
+ | elif [ " | ||
+ | val=" | ||
+ | fi | ||
+ | export " | ||
+ | unset " | ||
+ | } | ||
+ | |||
+ | # see https:// | ||
+ | _mongod_hack_have_arg() { | ||
+ | local checkArg=" | ||
+ | local arg | ||
+ | for arg; do | ||
+ | case " | ||
+ | " | ||
+ | return 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | return 1 | ||
+ | } | ||
+ | # _mongod_hack_get_arg_val ' | ||
+ | _mongod_hack_get_arg_val() { | ||
+ | local checkArg=" | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | case " | ||
+ | " | ||
+ | echo " | ||
+ | return 0 | ||
+ | ;; | ||
+ | " | ||
+ | echo " | ||
+ | return 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | return 1 | ||
+ | } | ||
+ | declare -a mongodHackedArgs | ||
+ | # _mongod_hack_ensure_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_arg() { | ||
+ | local ensureArg=" | ||
+ | mongodHackedArgs=( " | ||
+ | if ! _mongod_hack_have_arg " | ||
+ | mongodHackedArgs+=( " | ||
+ | fi | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_no_arg() { | ||
+ | local ensureNoArg=" | ||
+ | mongodHackedArgs=() | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | if [ " | ||
+ | continue | ||
+ | fi | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_no_arg_val() { | ||
+ | local ensureNoArg=" | ||
+ | mongodHackedArgs=() | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | case " | ||
+ | " | ||
+ | shift # also skip the value | ||
+ | continue | ||
+ | ;; | ||
+ | " | ||
+ | # value is already included | ||
+ | continue | ||
+ | ;; | ||
+ | esac | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_arg_val ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_arg_val() { | ||
+ | local ensureArg=" | ||
+ | local ensureVal=" | ||
+ | _mongod_hack_ensure_no_arg_val " | ||
+ | mongodHackedArgs+=( " | ||
+ | } | ||
+ | |||
+ | # _js_escape 'some " | ||
+ | _js_escape() { | ||
+ | jq --null-input --arg ' | ||
+ | } | ||
+ | |||
+ | jsonConfigFile=" | ||
+ | tempConfigFile=" | ||
+ | _parse_config() { | ||
+ | if [ -s " | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | local configPath | ||
+ | if configPath=" | ||
+ | # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) | ||
+ | # see https:// | ||
+ | mongo --norc --nodb --quiet --eval " | ||
+ | jq ' | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | return 1 | ||
+ | } | ||
+ | dbPath= | ||
+ | _dbPath() { | ||
+ | if [ -n " | ||
+ | echo " | ||
+ | return | ||
+ | fi | ||
+ | |||
+ | if ! dbPath=" | ||
+ | if _parse_config " | ||
+ | dbPath=" | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | if _mongod_hack_have_arg --configsvr " | ||
+ | _parse_config " | ||
+ | && clusterRole=" | ||
+ | && [ " | ||
+ | }; then | ||
+ | # if running as config server, then the default dbpath is / | ||
+ | # https:// | ||
+ | dbPath=/ | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | : " | ||
+ | |||
+ | echo " | ||
+ | } | ||
+ | |||
+ | if [ " | ||
+ | file_env ' | ||
+ | file_env ' | ||
+ | # pre-check a few factors to see if it's even worth bothering with initdb | ||
+ | shouldPerformInitdb= | ||
+ | if [ " | ||
+ | # if we have a username/ | ||
+ | _mongod_hack_ensure_arg ' | ||
+ | set -- " | ||
+ | shouldPerformInitdb=' | ||
+ | elif [ " | ||
+ | cat >&2 << | ||
+ | error: missing ' | ||
+ | both must be specified for a user to be created | ||
+ | EOF | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | # if we've got any / | ||
+ | for f in / | ||
+ | case " | ||
+ | *.sh|*.js) # this should match the set of files we check for below | ||
+ | shouldPerformInitdb=" | ||
+ | break | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | # check for a few known paths (to determine whether we've already initialized and should thus skip our initdb scripts) | ||
+ | if [ -n " | ||
+ | dbPath=" | ||
+ | for path in \ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ; do | ||
+ | if [ -e " | ||
+ | shouldPerformInitdb= | ||
+ | break | ||
+ | fi | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | if [ -n " | ||
+ | mongodHackedArgs=( " | ||
+ | if _parse_config " | ||
+ | _mongod_hack_ensure_arg_val --config " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 " | ||
+ | _mongod_hack_ensure_arg_val --port 27017 " | ||
+ | _mongod_hack_ensure_no_arg --bind_ip_all " | ||
+ | |||
+ | # remove " | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_no_arg --auth " | ||
+ | if [ " | ||
+ | _mongod_hack_ensure_no_arg_val --replSet " | ||
+ | fi | ||
+ | |||
+ | sslMode=" | ||
+ | _mongod_hack_ensure_arg_val --sslMode " | ||
+ | |||
+ | if stat "/ | ||
+ | # https:// | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_arg_val --logpath "/ | ||
+ | else | ||
+ | initdbLogPath=" | ||
+ | echo >&2 " | ||
+ | _mongod_hack_ensure_arg_val --logpath " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg --logappend " | ||
+ | |||
+ | pidfile=" | ||
+ | rm -f " | ||
+ | _mongod_hack_ensure_arg_val --pidfilepath " | ||
+ | |||
+ | " | ||
+ | |||
+ | mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) | ||
+ | |||
+ | # check to see that our " | ||
+ | # https:// | ||
+ | tries=30 | ||
+ | while true; do | ||
+ | if ! { [ -s " | ||
+ | # bail ASAP if " | ||
+ | echo >&2 | ||
+ | echo >&2 " | ||
+ | echo >&2 | ||
+ | exit 1 | ||
+ | fi | ||
+ | if " | ||
+ | # success! | ||
+ | break | ||
+ | fi | ||
+ | (( tries-- )) | ||
+ | if [ " | ||
+ | echo >&2 | ||
+ | echo >&2 " | ||
+ | echo >&2 | ||
+ | exit 1 | ||
+ | fi | ||
+ | sleep 1 | ||
+ | done | ||
+ | |||
+ | if [ " | ||
+ | rootAuthDatabase=' | ||
+ | |||
+ | " | ||
+ | db.createUser({ | ||
+ | user: $(_js_escape " | ||
+ | pwd: $(_js_escape " | ||
+ | roles: [ { role: ' | ||
+ | }) | ||
+ | EOJS | ||
+ | fi | ||
+ | |||
+ | export MONGO_INITDB_DATABASE=" | ||
+ | |||
+ | echo | ||
+ | for f in / | ||
+ | case " | ||
+ | *.sh) echo "$0: running $f"; . " | ||
+ | *.js) echo "$0: running $f"; " | ||
+ | *) echo "$0: ignoring $f" ;; | ||
+ | esac | ||
+ | echo | ||
+ | done | ||
+ | |||
+ | " | ||
+ | rm -f " | ||
+ | |||
+ | echo | ||
+ | echo ' | ||
+ | echo | ||
+ | fi | ||
+ | |||
+ | # MongoDB 3.6+ defaults to localhost-only binding | ||
+ | if mongod --help 2>&1 | grep -q -- --bind_ip_all; | ||
+ | haveBindIp= | ||
+ | if _mongod_hack_have_arg --bind_ip " | ||
+ | haveBindIp=1 | ||
+ | elif _parse_config " | ||
+ | haveBindIp=1 | ||
+ | fi | ||
+ | if [ -z " | ||
+ | # so if no " | ||
+ | set -- " | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | unset " | ||
+ | fi | ||
+ | |||
+ | rm -f " | ||
+ | |||
+ | exec " | ||
+ | </ | ||
+ | |||
+ | Examinons chaque commande dans le Dockerfile : | ||
+ | |||
+ | ====1.2 - FROM==== | ||
+ | |||
+ | < | ||
+ | FROM ubuntu: | ||
+ | </ | ||
+ | |||
+ | Cette ligne définit l' | ||
+ | |||
+ | ====1.3 - RUN==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | |||
+ | RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | ||
+ | |||
+ | RUN set -eux; \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | ca-certificates \ | ||
+ | jq \ | ||
+ | numactl \ | ||
+ | ; \ | ||
+ | if ! command -v ps > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends procps; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | ... | ||
+ | RUN set -ex; \ | ||
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; | ||
+ | gpg --batch --verify / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | chmod +x / | ||
+ | gosu --version; \ | ||
+ | gosu nobody true; \ | ||
+ | \ | ||
+ | wget -O /js-yaml.js " | ||
+ | # TODO some sort of download verification here | ||
+ | \ | ||
+ | apt-get purge -y --auto-remove wget | ||
+ | |||
+ | RUN mkdir / | ||
+ | ... | ||
+ | |||
+ | RUN set -ex; \ | ||
+ | export GNUPGHOME=" | ||
+ | for key in $GPG_KEYS; do \ | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys " | ||
+ | done; \ | ||
+ | gpg --batch --export $GPG_KEYS > / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | apt-key list | ||
+ | ... | ||
+ | RUN set -x \ | ||
+ | && apt-get update \ | ||
+ | && apt-get install -y \ | ||
+ | ${MONGO_PACKAGE}=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ | ||
+ | && rm -rf / | ||
+ | && rm -rf / | ||
+ | && mv / | ||
+ | |||
+ | RUN mkdir -p /data/db / | ||
+ | && chown -R mongodb: | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Cette commande lance un processus dans la construction de l' | ||
+ | |||
+ | Il existe un autre syntaxe de la commande RUN appelé le format exec, à savoir : | ||
+ | |||
+ | RUN ["/ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** : La commande RUN est utilisée pour exécuter une commande passée en argument lors de la compilation de l' | ||
+ | </ | ||
+ | |||
+ | ====1.4 - ENV==== | ||
+ | |||
+ | Cette commande permet de fixer la valeur d'une variable d' | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | ENV GOSU_VERSION 1.11 | ||
+ | # grab " | ||
+ | ENV JSYAML_VERSION 3.13.0 | ||
+ | ... | ||
+ | |||
+ | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B | ||
+ | ... | ||
+ | |||
+ | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} | ||
+ | |||
+ | ENV MONGO_MAJOR 4.1 | ||
+ | ENV MONGO_VERSION 4.1.95 | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | **et** dans les conteneurs générés à partir de l' | ||
+ | |||
+ | ====1.5 - VOLUME==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | VOLUME /data/db / | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Cette commande expose les répertoires passés en argument afin qu'ils puissent être mappés vers des répertoires sur la machine hôte ou ailleurs, tel que nous avons vu avec l' | ||
+ | |||
+ | ====1.6 - COPY==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | COPY docker-entrypoint.sh / | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Cette commande permet de récupérer les fichiers dans le contexte et de les copier dans l' | ||
+ | |||
+ | **Attention** : tous les fichiers dans le contexte sont inclus dans l' | ||
+ | |||
+ | Il est possible d' | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Il existe une autre commande similaire à COPY : ADD. ADD est une commande qui n'est plus recommendé sauf dans le cas de cas spécifiques. Notez que dans le cas de l' | ||
+ | </ | ||
+ | |||
+ | ====1.7 - ENTRYPOINT==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | ENTRYPOINT [" | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Cette commande stipule la commande qui sera exécutée lors du démarrage du conteneur. | ||
+ | |||
+ | Deux cas de figure se présentent : | ||
+ | |||
+ | * ENTRYPOINT suivi d'une chaîne - un shell est démarré pour exécuter la chaîne, | ||
+ | * ENTRYPOINT suivi d'une table JSON ( comme ci-dessus ) au format ENTRYPOINT [" | ||
+ | |||
+ | Dans le fichier **docker-entrypoint.sh** : | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | originalArgOne=" | ||
+ | |||
+ | # allow the container to be started with `--user` | ||
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
+ | |||
+ | # make sure we can write to stdout and stderr as " | ||
+ | # (for our " | ||
+ | chown --dereference mongodb "/ | ||
+ | # ignore errors thanks to https:// | ||
+ | |||
+ | exec gosu mongodb " | ||
+ | fi | ||
+ | |||
+ | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | ||
+ | # https:// | ||
+ | if [[ " | ||
+ | numa=' | ||
+ | if $numa true &> /dev/null; then | ||
+ | set -- $numa " | ||
+ | fi | ||
+ | fi | ||
+ | ... | ||
+ | exec " | ||
+ | </ | ||
+ | |||
+ | si la valeur du paramètre passé à entrypoint.sh est **mongod**, le script affecte l' | ||
+ | |||
+ | Ce fichier finit par " | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez que la compilation d'une image se fait à l' | ||
+ | </ | ||
+ | |||
+ | ====1.8 - EXPOSE==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | EXPOSE 27017 | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Cette commande permet d' | ||
+ | |||
+ | ====1.9 - CMD==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | CMD [" | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Ceci représente la valeur du paramètre par défaut si aucun paramètre n'est spécifié à la fin de la commande docker run. | ||
+ | |||
+ | ====1.10 - Autres Commandes==== | ||
+ | |||
+ | Le Dockerfile peut aussi contenir les commandes suivantes : | ||
+ | |||
+ | * **WORKDIR**, | ||
+ | * Cette commande fixe le répertoire de travil lors de la compilation d'une image. Elle peut apparaître plusieurs fois dans le Dockerfile permettant ainsi l' | ||
+ | * **LABEL**, | ||
+ | * Cette commande permet de définir des couples clef/valeur à inclure dans les méta-données décrivant l' | ||
+ | |||
+ | |||
+ | Lancez maintenant la compilation de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | [+] Building 56.9s (15/15) FINISHED | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 3.55kB | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => [internal] load build context | ||
+ | => => transferring context: 42B 0.0s | ||
+ | => [ 1/10] FROM docker.io/ | ||
+ | => CACHED [ 2/10] RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | ||
+ | => CACHED [ 3/10] RUN set -eux; apt-get update; | ||
+ | => [ 4/10] RUN set -ex; | ||
+ | => [ 5/10] RUN mkdir / | ||
+ | => [ 6/10] RUN set -ex; export GNUPGHOME=" | ||
+ | => [ 7/10] RUN echo "deb http:// | ||
+ | => [ 8/10] RUN set -x && apt-get update | ||
+ | => [ 9/10] RUN mkdir -p /data/db / | ||
+ | => [10/10] COPY docker-entrypoint.sh / | ||
+ | => exporting to image 2.6s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | </ | ||
+ | |||
+ | Consultez la liste de images : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | REPOSITORY | ||
+ | < | ||
+ | ittraining/ | ||
+ | ubuntu | ||
+ | nginx latest | ||
+ | hello-world | ||
+ | centos | ||
+ | </ | ||
+ | |||
+ | Notez que l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | REPOSITORY | ||
+ | i2tch/ | ||
+ | ittraining/ | ||
+ | ubuntu | ||
+ | nginx latest | ||
+ | hello-world | ||
+ | centos | ||
+ | </ | ||
+ | |||
+ | Démarrez un conteneur à partir de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | 3c578ea2a0428a07b60dac3b63d806351dffa2bb05224bcf7d12f1189766f38e | ||
+ | docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: " | ||
+ | |||
+ | root@debian11: | ||
+ | total 16 | ||
+ | -rw-r--r-- 1 root root 10971 Dec 10 16:57 docker-entrypoint.sh | ||
+ | -rw-r--r-- 1 root root 3514 Dec 10 17:09 Dockerfile | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez que le fichier docker-entrypoint.sh n'est pas exécutable ! | ||
+ | </ | ||
+ | |||
+ | Recompilez donc l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | mongo1 | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | [+] Building 0.8s (15/15) FINISHED | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 3.55kB | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => [ 1/10] FROM docker.io/ | ||
+ | => [internal] load build context | ||
+ | => => transferring context: 11.02kB | ||
+ | => CACHED [ 2/10] RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | ||
+ | => CACHED [ 3/10] RUN set -eux; apt-get update; | ||
+ | => CACHED [ 4/10] RUN set -ex; | ||
+ | => CACHED [ 5/10] RUN mkdir / | ||
+ | => CACHED [ 6/10] RUN set -ex; export GNUPGHOME=" | ||
+ | => CACHED [ 7/10] RUN echo "deb http:// | ||
+ | => CACHED [ 8/10] RUN set -x && apt-get update | ||
+ | => CACHED [ 9/10] RUN mkdir -p /data/db / | ||
+ | => [10/10] COPY docker-entrypoint.sh / | ||
+ | => exporting to image 0.1s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez ici les lignes **CACHED**. Il est cependant possible de ne pas utiliser le cache en stipulant **--no-cache**. Notez aussi l' | ||
+ | </ | ||
+ | |||
+ | Consultez la liste des images de nouveau et renommez votre dernière image : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | REPOSITORY | ||
+ | < | ||
+ | i2tch/ | ||
+ | ittraining/ | ||
+ | ubuntu | ||
+ | nginx latest | ||
+ | hello-world | ||
+ | centos | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | REPOSITORY | ||
+ | i2tch/ | ||
+ | i2tch/ | ||
+ | ittraining/ | ||
+ | ubuntu | ||
+ | nginx latest | ||
+ | hello-world | ||
+ | centos | ||
+ | </ | ||
+ | |||
+ | Lancez un conteneur à partir de la dernière image : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | 880733c6bdc33a9a8fa6ae171e977cf745ea9a1b9cfc914992a2d0d3f8cd9d39 | ||
+ | </ | ||
+ | |||
+ | Utilisez la commande **docker ps** pour visualiser si le processus mongodb est bien démarré : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | </ | ||
+ | |||
+ | Connectez-vous à mongodb à partir de votre machine hôte : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | root@debian11: | ||
+ | MongoDB shell version v4.0.28 | ||
+ | connecting to: mongodb:// | ||
+ | Implicit session: session { " | ||
+ | MongoDB server version: 4.1.9 | ||
+ | WARNING: shell and server versions do not match | ||
+ | Server has startup warnings: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | 2023-12-10T16: | ||
+ | --- | ||
+ | Enable MongoDB' | ||
+ | metrics about your deployment (disk utilization, | ||
+ | |||
+ | The monitoring data will be available on a MongoDB website with a unique URL accessible to you | ||
+ | and anyone you share the URL with. MongoDB may use this information to make product | ||
+ | improvements and to suggest MongoDB products and deployment options to you. | ||
+ | |||
+ | To enable free monitoring, run the following command: db.enableFreeMonitoring() | ||
+ | To permanently disable this reminder, run the following command: db.disableFreeMonitoring() | ||
+ | --- | ||
+ | |||
+ | > exit | ||
+ | bye | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | =====LAB #2 - Créer un Dockerfile===== | ||
+ | |||
+ | ====2.1 - Création et test du script==== | ||
+ | |||
+ | Créez un répertoire nommé myDocker : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Créez le fichier myEntrypoint.sh : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | #!/bin/bash | ||
+ | if [ -z " | ||
+ | echo "The variable myVariable must have a value" | ||
+ | return 1 | ||
+ | fi | ||
+ | |||
+ | while true; | ||
+ | do | ||
+ | echo $1 \($(date +%H: | ||
+ | sleep " | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | Testez ce script : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | Hello! (18:01:54) | ||
+ | Hello! (18:01:57) | ||
+ | Hello! (18:02:00) | ||
+ | Hello! (18:02:03) | ||
+ | Hello! (18:02:06) | ||
+ | ^C | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Rendez ce script exécutable : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Créez maintenant le fichier **Dockerfile** dans le répertoire **~/ | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | FROM centos: | ||
+ | MAINTAINER Team IT Training " | ||
+ | COPY myEntrypoint.sh / | ||
+ | ENV myVariable 3 | ||
+ | ENTRYPOINT ["/ | ||
+ | CMD [" | ||
+ | </ | ||
+ | |||
+ | Générez maintenant l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | [+] Building 0.8s (7/7) FINISHED | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 211B 0.0s | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => [internal] load build context | ||
+ | => => transferring context: 224B 0.0s | ||
+ | => [1/2] FROM docker.io/ | ||
+ | => [2/2] COPY myEntrypoint.sh / | ||
+ | => exporting to image 0.1s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | => => naming to docker.io/ | ||
+ | </ | ||
+ | |||
+ | Lancez le conteneur : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | mycommand (17:05:57) | ||
+ | mycommand (17:06:00) | ||
+ | mycommand (17:06:03) | ||
+ | ^Cmycommand (17:06:06) | ||
+ | mycommand (17:06:09) | ||
+ | mycommand (17:06:12) | ||
+ | ^P^Q | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez que **^C** n'a aucun effet. Pour se détacher du conteneur il convient d' | ||
+ | </ | ||
+ | |||
+ | Constatez que le conteneur est toujours en cours de fonctionnement : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 97fe360bb1d6 | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | |||
+ | root@debian11: | ||
+ | mycommand (17:10:30) | ||
+ | mycommand (17:10:33) | ||
+ | mycommand (17:10:36) | ||
+ | mycommand (17:10:39) | ||
+ | mycommand (17:10:42) | ||
+ | mycommand (17:10:45) | ||
+ | mycommand (17:10:48) | ||
+ | mycommand (17:10:51) | ||
+ | mycommand (17:10:54) | ||
+ | mycommand (17:10:57) | ||
+ | </ | ||
+ | |||
+ | Arrêtez le conteneur : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | </ | ||
+ | |||
+ | Démarrez le conteneur : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 97fe360bb1d6 | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | </ | ||
+ | |||
+ | Mettez le conteneur en pause : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 97fe360bb1d6 | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | </ | ||
+ | |||
+ | Supprimez la pause : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | CONTAINER ID | ||
+ | 97fe360bb1d6 | ||
+ | 880733c6bdc3 | ||
+ | 885f75b6aa57 | ||
+ | 04d910a3c93d | ||
+ | </ | ||
+ | |||
+ | Lancez maintenant le conteneur avec un paramètre : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | fd5ac836f674fe0bf7b5056e851cd15e4762a5e41b05e00d384bede5234e1f5f | ||
+ | |||
+ | root@debian11: | ||
+ | Up and Running (17:14:23) | ||
+ | Up and Running (17:14:26) | ||
+ | Up and Running (17:14:29) | ||
+ | Up and Running (17:14:32) | ||
+ | Up and Running (17:14:35) | ||
+ | Up and Running (17:14:38) | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Changez la valeur de la variable d' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | myDocker | ||
+ | |||
+ | root@debian11: | ||
+ | a9e02a8bb39df9d5c84fc1d58643bc38c228b0562731792e2356a801b50a9a14 | ||
+ | |||
+ | root@debian11: | ||
+ | mycommand (17:15:35) | ||
+ | mycommand (17:15:36) | ||
+ | mycommand (17:15:37) | ||
+ | mycommand (17:15:38) | ||
+ | mycommand (17:15:39) | ||
+ | mycommand (17:15:40) | ||
+ | mycommand (17:15:41) | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | ====2.2 - Bonnes Pratiques liées au Cache==== | ||
+ | |||
+ | ===Opérations Non-Idempotentes=== | ||
+ | |||
+ | Créez un répertoire **bestp** ainsi que le fichier Dockerfile suivant : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | FROM ubuntu: | ||
+ | RUN date +%N > /tmp/moment | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/ | ||
+ | </ | ||
+ | |||
+ | Le fichier Dokerfile contient une opération non idempotente. | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** : Une opération idempotente est une opération qui aboutit systématiquement au même résultat quand elle est lancée dans le même contexte. | ||
+ | </ | ||
+ | |||
+ | Compilez l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | [+] Building 0.9s (6/6) FINISHED | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 123B 0.0s | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => [1/2] FROM docker.io/ | ||
+ | => [2/2] RUN date +%N > / | ||
+ | => exporting to image 0.1s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | => => naming to docker.io/ | ||
+ | </ | ||
+ | |||
+ | Exécuter maintenant un premier conteneur à partir de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | 771723987 | ||
+ | </ | ||
+ | |||
+ | Supprimez maintenant le conteneur et relancez la compilation de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | test1 | ||
+ | |||
+ | root@debian11: | ||
+ | [+] Building 0.3s (6/6) FINISHED | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 123B 0.0s | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => [1/2] FROM docker.io/ | ||
+ | => CACHED [2/2] RUN date +%N > / | ||
+ | => exporting to image 0.0s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | => => naming to docker.io/ | ||
+ | </ | ||
+ | |||
+ | Lancez un conteneur à partir de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | 771723987 | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez que les deux sorties des conteneurs sont identiques malgré le fait que la valeur de la commande date aurait du modifier le résultat obtenu lors de l' | ||
+ | </ | ||
+ | |||
+ | Pour contourner ce problème, il est possible d' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | FROM ubuntu: | ||
+ | RUN date +%N > /tmp/moment \ | ||
+ | && echo " | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/ | ||
+ | </ | ||
+ | |||
+ | Supprimez maintenant le conteneur et relancez la compilation de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | test1 | ||
+ | |||
+ | root@debian11: | ||
+ | [+] Building 0.7s (6/6) FINISHED | ||
+ | => [internal] load .dockerignore | ||
+ | => => transferring context: 2B 0.0s | ||
+ | => [internal] load build definition from Dockerfile | ||
+ | => => transferring dockerfile: 159B 0.0s | ||
+ | => [internal] load metadata for docker.io/ | ||
+ | => CACHED [1/2] FROM docker.io/ | ||
+ | => [2/2] RUN date +%N > / | ||
+ | => exporting to image 0.1s | ||
+ | => => exporting layers | ||
+ | => => writing image sha256: | ||
+ | => => naming to docker.io/ | ||
+ | </ | ||
+ | |||
+ | Lancez un conteneur à partir de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | 063819144 | ||
+ | </ | ||
+ | |||
+ | =====LAB #3 - Installer un Registre Privé===== | ||
+ | |||
+ | ====3.1 - Installer un Registre Local==== | ||
+ | |||
+ | Pour installer un registre privé, il convient d' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | Unable to find image ' | ||
+ | latest: Pulling from library/ | ||
+ | c926b61bad3b: | ||
+ | 5501dced60f8: | ||
+ | e875fe5e6b9c: | ||
+ | 21f4bf2f86f9: | ||
+ | 98513cca25bb: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for registry: | ||
+ | 272df4a849bcbc58a70d6c8e1e74751f24e485fd8ad6817427ef180b9f28b5f8 | ||
+ | </ | ||
+ | |||
+ | Utilisez maintenant **lynx** à partir d'un terminal de votre machine **hôte Docker** pour vérifier que le registre est actif : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | {}root@debian11: | ||
+ | </ | ||
+ | |||
+ | <WRAP center round important 50%> | ||
+ | **Important** - Notez la réponse du serveur est **{}** soit une liste JSON vide. | ||
+ | </ | ||
+ | |||
+ | Renommez l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Envoyez votre image **localhost: | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | Using default tag: latest | ||
+ | The push refers to repository [localhost: | ||
+ | f981bd64e799: | ||
+ | 74ddd0ec08fa: | ||
+ | latest: digest: sha256: | ||
+ | </ | ||
+ | |||
+ | Constatez maintenant la présence de l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | {" | ||
+ | </ | ||
+ | |||
+ | ====3.2 - Créer un Serveur de Registre Dédié==== | ||
+ | |||
+ | Actuellement, | ||
+ | |||
+ | Connectez-vous à la VM **CentOS_10.0.2.45_SSH** à partir de votre VM **Debian_10.0.2.46_SSH** : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | trainee@10.0.2.45' | ||
+ | Activate the web console with: systemctl enable --now cockpit.socket | ||
+ | |||
+ | Last login: Wed Nov 15 05:24:16 2023 from 10.0.2.1 | ||
+ | [trainee@centos8 ~]$ | ||
+ | </ | ||
+ | |||
+ | Devenez root : | ||
+ | |||
+ | < | ||
+ | [trainee@centos8 ~]$ su - | ||
+ | Password: fenestros | ||
+ | [root@centos8 ~]# | ||
+ | </ | ||
+ | |||
+ | Modifiez le nom d' | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# nmcli general hostname myregistry.i2tch.loc | ||
+ | [root@centos8 ~]# hostname | ||
+ | myregistry.i2tch.loc | ||
+ | </ | ||
+ | |||
+ | Editez le fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# vi /etc/hosts | ||
+ | [root@centos8 ~]# cat /etc/hosts | ||
+ | 127.0.0.1 | ||
+ | ::1 | ||
+ | 10.0.2.45 | ||
+ | 10.0.2.46 | ||
+ | </ | ||
+ | |||
+ | Créez maintenant un certificat auto-signé avec **openssl** : | ||
+ | |||
+ | < | ||
+ | [root@centos8 ~]# cd / | ||
+ | |||
+ | [root@centos8 /]# vi myconfig.cnf | ||
+ | |||
+ | [root@centos8 /]# cat myconfig.cnf | ||
+ | [ req ] | ||
+ | distinguished_name = dn | ||
+ | x509_extensions = extensions | ||
+ | prompt = no | ||
+ | |||
+ | [ extensions ] | ||
+ | subjectAltName = DNS: | ||
+ | |||
+ | [ dn ] | ||
+ | 0.DC = loc | ||
+ | 1.DC = i2tch | ||
+ | commonName = i2tch.loc | ||
+ | |||
+ | [root@centos8 ~]# mkdir certs && openssl req -config myconfig.cnf -newkey rsa:4096 -nodes -sha256 -keyout certs/ | ||
+ | Generating a RSA private key | ||
+ | ...............................................................................................................................................................................................++++ | ||
+ | ......++++ | ||
+ | writing new private key to ' | ||
+ | ----- | ||
+ | |||
+ | [root@centos8 /]# ls certs/ | ||
+ | domain.crt | ||
+ | </ | ||
+ | |||
+ | Déconnectez-vous de la VM **CentOS8_10.0.2.45_SSH** : | ||
+ | |||
+ | < | ||
+ | [root@centos8 /]# exit | ||
+ | logout | ||
+ | [trainee@centos8 ~]$ exit | ||
+ | logout | ||
+ | Connection to 10.0.2.45 closed. | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Re-connectez-vous à la VM **CentOS8_10.0.2.45_SSH** : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | trainee@10.0.2.45' | ||
+ | Activate the web console with: systemctl enable --now cockpit.socket | ||
+ | |||
+ | Last login: Fri Dec 15 01:07:37 2023 from 10.0.2.46 | ||
+ | [trainee@centos8 ~]$ | ||
+ | </ | ||
+ | |||
+ | Devenez root : | ||
+ | |||
+ | < | ||
+ | [trainee@myregistry ~]$ su - | ||
+ | Password: fenestros | ||
+ | [root@myregistry ~]# | ||
+ | </ | ||
+ | |||
+ | Créez un conteneur en mode sécurisé avec TLS à partir de l' | ||
+ | |||
+ | < | ||
+ | [root@myregistry ~]# docker run -d -p 5000:5000 --name registry -v / | ||
+ | Unable to find image ' | ||
+ | latest: Pulling from library/ | ||
+ | c926b61bad3b: | ||
+ | 5501dced60f8: | ||
+ | e875fe5e6b9c: | ||
+ | 21f4bf2f86f9: | ||
+ | 98513cca25bb: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for registry: | ||
+ | bf0d4fe9fcb121f9c2d9e85b8f2bb54b01397602ef0dcefdfc71327acf832fec | ||
+ | |||
+ | [root@myregistry ~]# docker ps -a | ||
+ | CONTAINER ID | ||
+ | bf0d4fe9fcb1 | ||
+ | 90267aac9800 | ||
+ | </ | ||
+ | |||
+ | Envoyez une copie du fichier **/ | ||
+ | |||
+ | < | ||
+ | [root@myregistry ~]# scp / | ||
+ | The authenticity of host ' | ||
+ | ECDSA key fingerprint is SHA256: | ||
+ | Are you sure you want to continue connecting (yes/ | ||
+ | Warning: Permanently added ' | ||
+ | trainee@10.0.2.46' | ||
+ | domain.crt | ||
+ | </ | ||
+ | |||
+ | ===Configurer le Client=== | ||
+ | |||
+ | Sortez de la VM **CentOS8_10.0.2.45_SSH** : | ||
+ | |||
+ | < | ||
+ | [root@myregistry ~]# exit | ||
+ | logout | ||
+ | [trainee@myregistry ~]$ exit | ||
+ | logout | ||
+ | Connection to 10.0.2.45 closed. | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Supprimez le conteneur **registry** : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | registry | ||
+ | </ | ||
+ | |||
+ | ainsi que l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | Untagged: registry: | ||
+ | Untagged: registry@sha256: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | </ | ||
+ | |||
+ | Renommez l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | REPOSITORY | ||
+ | testcache | ||
+ | < | ||
+ | i2tch/ | ||
+ | localhost: | ||
+ | myregistry.i2tch.loc: | ||
+ | i2tch/ | ||
+ | i2tch/ | ||
+ | ittraining/ | ||
+ | ubuntu | ||
+ | nginx latest | ||
+ | hello-world | ||
+ | centos | ||
+ | </ | ||
+ | |||
+ | Editez le fichier **/ | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | 127.0.0.1 | ||
+ | 10.0.2.46 | ||
+ | 10.0.2.45 | ||
+ | |||
+ | # The following lines are desirable for IPv6 capable hosts | ||
+ | ::1 | ||
+ | ff02::1 ip6-allnodes | ||
+ | ff02::2 ip6-allrouters | ||
+ | </ | ||
+ | |||
+ | Déplacez le fichier **/ | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Créez le fichier **/ | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | |||
+ | root@debian11: | ||
+ | {" | ||
+ | </ | ||
+ | |||
+ | Re-démarrez le service docker : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | </ | ||
+ | |||
+ | Testez la réponse du registre : | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | {}root@debian11: | ||
+ | </ | ||
+ | |||
+ | Finalement, envoyez l' | ||
+ | |||
+ | < | ||
+ | root@debian11: | ||
+ | Using default tag: latest | ||
+ | The push refers to repository [myregistry.i2tch.loc: | ||
+ | f981bd64e799: | ||
+ | 74ddd0ec08fa: | ||
+ | latest: digest: sha256: | ||
+ | </ | ||
+ | |||
+ | ----- | ||
+ | |||
+ | Copyright © 2024 Hugh Norris. |