Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
elearning:workbooks:docker3:drf02 [2021/11/21 11:38] – created adminelearning:workbooks:docker3:drf02 [2024/02/21 13:41] (Version actuelle) admin
Ligne 1: Ligne 1:
 ~~PDF:LANDSCAPE~~ ~~PDF:LANDSCAPE~~
  
-Version : **2021.01**+Version : **2024.01**
  
 Dernière mise-à-jour : ~~LASTMOD~~ Dernière mise-à-jour : ~~LASTMOD~~
  
-======DOF603 - Gérer les Images Docker======+======DOF603 - Gérer et Stocker les Images Docker======
  
 =====Contenu du Module===== =====Contenu du Module=====
  
-  * **DOF603 - Gérer les Images Docker**+  * **DOF603 - Gérer et Stocker les Images Docker**
     * Contenu du Module     * Contenu du Module
     * LAB #1 - Re-créer une image officielle docker     * LAB #1 - Re-créer une image officielle docker
Ligne 25: Ligne 25:
       * 2.1 - Création et test du script       * 2.1 - Création et test du script
       * 2.2 - Bonnes Pratiques liées au Cache       * 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===== =====LAB #1 - Re-créer une image officielle docker=====
Ligne 33: Ligne 37:
  
 <code> <code>
-root@debian9:~# mkdir mongodb +root@debian11:~# mkdir mongodb 
-root@debian9:~# cd mongodb/ +root@debian11:~# cd mongodb/ 
-root@debian9:~/mongodb# touch Dockerfile docker-entrypoint.sh+root@debian11:~/mongodb# touch Dockerfile docker-entrypoint.sh
 </code> </code>
  
 Le Docker file contient les instructions nécessaires pour la contruction de l'image : Le Docker file contient les instructions nécessaires pour la contruction de l'image :
  
-<file txt Dockerfile>+<code> 
 +root@debian11:~/mongodb# vi Dockerfile  
 +root@debian11:~/mongodb# cat Dockerfile 
 FROM ubuntu:bionic FROM ubuntu:bionic
  
Ligne 47: Ligne 53:
  
 RUN set -eux; \ RUN set -eux; \
- apt-get update; \ +        apt-get update; \ 
- apt-get install -y --no-install-recommends \ +        apt-get install -y --no-install-recommends \ 
- ca-certificates \ +                ca-certificates \ 
- jq \ +                jq \ 
- numactl \ +                numactl \ 
- ; \ +        ; \ 
- if ! command -v ps > /dev/null; then \ +        if ! command -v ps > /dev/null; then \ 
- apt-get install -y --no-install-recommends procps; \ +                apt-get install -y --no-install-recommends procps; \ 
- fi; \ +        fi; \ 
- rm -rf /var/lib/apt/lists/*+        rm -rf /var/lib/apt/lists/*
  
 # grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases) # grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases)
Ligne 64: Ligne 70:
  
 RUN set -ex; \ RUN set -ex; \
- +        
- apt-get update; \ +        apt-get update; \ 
- apt-get install -y --no-install-recommends \ +        apt-get install -y --no-install-recommends \ 
- wget \ +                wget \ 
- ; \ +        ; \ 
- if ! command -v gpg > /dev/null; then \ +        if ! command -v gpg > /dev/null; then \ 
- apt-get install -y --no-install-recommends gnupg dirmngr; \ +                apt-get install -y --no-install-recommends gnupg dirmngr; \ 
- fi; \ +        fi; \ 
- rm -rf /var/lib/apt/lists/*;+        rm -rf /var/lib/apt/lists/*;
-+        
- dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')";+        dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')";
- wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch";+        wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch";
- wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc";+        wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc";
- export GNUPGHOME="$(mktemp -d)"; \ +        export GNUPGHOME="$(mktemp -d)"; \ 
- gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4;+        gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4;
- # gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu;+        # gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu;
- command -v gpgconf && gpgconf --kill all || :; \ +        command -v gpgconf && gpgconf --kill all || :; \ 
- rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc;+        rm -r "$GNUPGHOME" /usr/local/bin/gosu.asc;
- chmod +x /usr/local/bin/gosu;+        chmod +x /usr/local/bin/gosu;
- gosu --version; \ +        gosu --version; \ 
- gosu nobody true; \ +        gosu nobody true; \ 
-+        
- wget -O /js-yaml.js "https://github.com/nodeca/js-yaml/raw/${JSYAML_VERSION}/dist/js-yaml.js"; \+        wget -O /js-yaml.js "https://github.com/nodeca/js-yaml/raw/${JSYAML_VERSION}/dist/js-yaml.js"; \
 # TODO some sort of download verification here # TODO some sort of download verification here
- +        
- apt-get purge -y --auto-remove wget+        apt-get purge -y --auto-remove wget
  
 RUN mkdir /docker-entrypoint-initdb.d RUN mkdir /docker-entrypoint-initdb.d
Ligne 95: Ligne 101:
 ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B
 RUN set -ex; \ RUN set -ex; \
- export GNUPGHOME="$(mktemp -d)"; \ +        export GNUPGHOME="$(mktemp -d)"; \ 
- for key in $GPG_KEYS; do \ +        for key in $GPG_KEYS; do \ 
- gpg --batch --keyserver pgp.mit.edu --recv-keys "$key";+                gpg --batch --keyserver pgp.mit.edu --recv-keys "$key";
- done; \ +        done; \ 
- gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg;+        gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg;
- command -v gpgconf && gpgconf --kill all || :; \ +        command -v gpgconf && gpgconf --kill all || :; \ 
- rm -r "$GNUPGHOME";+        rm -r "$GNUPGHOME";
- apt-key list+        apt-key list
  
 # Allow build-time overrides (eg. to build image with MongoDB Enterprise version) # Allow build-time overrides (eg. to build image with MongoDB Enterprise version)
Ligne 118: Ligne 124:
  
 RUN set -x \ RUN set -x \
- && apt-get update \ +        && apt-get update \ 
- && apt-get install -y \ +        && apt-get install -y \ 
- ${MONGO_PACKAGE}=$MONGO_VERSION \ +                ${MONGO_PACKAGE}=$MONGO_VERSION \ 
- ${MONGO_PACKAGE}-server=$MONGO_VERSION \ +                ${MONGO_PACKAGE}-server=$MONGO_VERSION \ 
- ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ +                ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ 
- ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ +                ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ 
- ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ +                ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ 
- && rm -rf /var/lib/apt/lists/* \ +        && rm -rf /var/lib/apt/lists/* \ 
- && rm -rf /var/lib/mongodb \ +        && rm -rf /var/lib/mongodb \ 
- && mv /etc/mongod.conf /etc/mongod.conf.orig+        && mv /etc/mongod.conf /etc/mongod.conf.orig
  
 RUN mkdir -p /data/db /data/configdb \ RUN mkdir -p /data/db /data/configdb \
- && chown -R mongodb:mongodb /data/db /data/configdb+        && chown -R mongodb:mongodb /data/db /data/configdb
 VOLUME /data/db /data/configdb VOLUME /data/db /data/configdb
  
Ligne 138: Ligne 144:
 EXPOSE 27017 EXPOSE 27017
 CMD ["mongod"] CMD ["mongod"]
-</file>+</code>
  
 Le fichier docker-entrypoint.sh sert à lancer le serveur mongodb dans le conteneur : Le fichier docker-entrypoint.sh sert à lancer le serveur mongodb dans le conteneur :
  
-<file txt docker-entrypoint.sh>+<code> 
 +root@debian11:~/mongodb# vi docker-entrypoint.sh 
 +root@debian11:~/mongodb# cat docker-entrypoint.sh
 #!/bin/bash #!/bin/bash
 set -Eeuo pipefail set -Eeuo pipefail
  
 if [ "${1:0:1}" = '-' ]; then if [ "${1:0:1}" = '-' ]; then
- set -- mongod "$@"+        set -- mongod "$@"
 fi fi
  
Ligne 155: Ligne 163:
 # all mongo* commands should be dropped to the correct user # all mongo* commands should be dropped to the correct user
 if [[ "$originalArgOne" == mongo* ]] && [ "$(id -u)" = '0' ]; then if [[ "$originalArgOne" == mongo* ]] && [ "$(id -u)" = '0' ]; then
- if [ "$originalArgOne" = 'mongod' ]; then +        if [ "$originalArgOne" = 'mongod' ]; then 
- find /data/configdb /data/db \! -user mongodb -exec chown mongodb '{}'+                find /data/configdb /data/db \! -user mongodb -exec chown mongodb '{}'
- fi+        fi
  
- # make sure we can write to stdout and stderr as "mongodb" +        # make sure we can write to stdout and stderr as "mongodb" 
- # (for our "initdb" code later; see "--logpath" below) +        # (for our "initdb" code later; see "--logpath" below) 
- chown --dereference mongodb "/proc/$$/fd/1" "/proc/$$/fd/2" || : +        chown --dereference mongodb "/proc/$$/fd/1" "/proc/$$/fd/2" || : 
- # ignore errors thanks to https://github.com/docker-library/mongo/issues/149+        # ignore errors thanks to https://github.com/docker-library/mongo/issues/149
  
- exec gosu mongodb "$BASH_SOURCE" "$@"+        exec gosu mongodb "$BASH_SOURCE" "$@"
 fi fi
  
Ligne 170: Ligne 178:
 # https://docs.mongodb.com/manual/administration/production-notes/#configuring-numa-on-linux # https://docs.mongodb.com/manual/administration/production-notes/#configuring-numa-on-linux
 if [[ "$originalArgOne" == mongo* ]]; then if [[ "$originalArgOne" == mongo* ]]; then
- numa='numactl --interleave=all' +        numa='numactl --interleave=all' 
- if $numa true &> /dev/null; then +        if $numa true &> /dev/null; then 
- set -- $numa "$@" +                set -- $numa "$@" 
- fi+        fi
 fi fi
  
Ligne 181: Ligne 189:
 #  "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature) #  "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
 file_env() { file_env() {
- local var="$1" +        local var="$1" 
- local fileVar="${var}_FILE" +        local fileVar="${var}_FILE" 
- local def="${2:-}" +        local def="${2:-}" 
- if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then +        if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then 
- echo >&2 "error: both $var and $fileVar are set (but are exclusive)" +                echo >&2 "error: both $var and $fileVar are set (but are exclusive)" 
- exit 1 +                exit 1 
- fi +        fi 
- local val="$def" +        local val="$def" 
- if [ "${!var:-}" ]; then +        if [ "${!var:-}" ]; then 
- val="${!var}" +                val="${!var}" 
- elif [ "${!fileVar:-}" ]; then +        elif [ "${!fileVar:-}" ]; then 
- val="$(< "${!fileVar}")" +                val="$(< "${!fileVar}")" 
- fi +        fi 
- export "$var"="$val" +        export "$var"="$val" 
- unset "$fileVar"+        unset "$fileVar"
 } }
  
 # see https://github.com/docker-library/mongo/issues/147 (mongod is picky about duplicated arguments) # see https://github.com/docker-library/mongo/issues/147 (mongod is picky about duplicated arguments)
 _mongod_hack_have_arg() { _mongod_hack_have_arg() {
- local checkArg="$1"; shift +        local checkArg="$1"; shift 
- local arg +        local arg 
- for arg; do +        for arg; do 
- case "$arg" in +                case "$arg" in 
- "$checkArg"|"$checkArg"=*) +                        "$checkArg"|"$checkArg"=*) 
- return 0 +                                return 0 
- ;; +                                ;; 
- esac +                esac 
- done +        done 
- return 1+        return 1
 } }
 # _mongod_hack_get_arg_val '--some-arg' "$@" # _mongod_hack_get_arg_val '--some-arg' "$@"
 _mongod_hack_get_arg_val() { _mongod_hack_get_arg_val() {
- local checkArg="$1"; shift +        local checkArg="$1"; shift 
- while [ "$#" -gt 0 ]; do +        while [ "$#" -gt 0 ]; do 
- local arg="$1"; shift +                local arg="$1"; shift 
- case "$arg" in +                case "$arg" in 
- "$checkArg"+                        "$checkArg"
- echo "$1" +                                echo "$1" 
- return 0 +                                return 0 
- ;; +                                ;; 
- "$checkArg"=*) +                        "$checkArg"=*) 
- echo "${arg#$checkArg=}" +                                echo "${arg#$checkArg=}" 
- return 0 +                                return 0 
- ;; +                                ;; 
- esac +                esac 
- done +        done 
- return 1+        return 1
 } }
 declare -a mongodHackedArgs declare -a mongodHackedArgs
Ligne 233: Ligne 241:
 # set -- "${mongodHackedArgs[@]}" # set -- "${mongodHackedArgs[@]}"
 _mongod_hack_ensure_arg() { _mongod_hack_ensure_arg() {
- local ensureArg="$1"; shift +        local ensureArg="$1"; shift 
- mongodHackedArgs=( "$@"+        mongodHackedArgs=( "$@"
- if ! _mongod_hack_have_arg "$ensureArg" "$@"; then +        if ! _mongod_hack_have_arg "$ensureArg" "$@"; then 
- mongodHackedArgs+=( "$ensureArg"+                mongodHackedArgs+=( "$ensureArg"
- fi+        fi
 } }
 # _mongod_hack_ensure_no_arg '--some-unwanted-arg' "$@" # _mongod_hack_ensure_no_arg '--some-unwanted-arg' "$@"
 # set -- "${mongodHackedArgs[@]}" # set -- "${mongodHackedArgs[@]}"
 _mongod_hack_ensure_no_arg() { _mongod_hack_ensure_no_arg() {
- local ensureNoArg="$1"; shift +        local ensureNoArg="$1"; shift 
- mongodHackedArgs=() +        mongodHackedArgs=() 
- while [ "$#" -gt 0 ]; do +        while [ "$#" -gt 0 ]; do 
- local arg="$1"; shift +                local arg="$1"; shift 
- if [ "$arg" = "$ensureNoArg" ]; then +                if [ "$arg" = "$ensureNoArg" ]; then 
- continue +                        continue 
- fi +                fi 
- mongodHackedArgs+=( "$arg"+                mongodHackedArgs+=( "$arg"
- done+        done
 } }
 # _mongod_hack_ensure_no_arg '--some-unwanted-arg' "$@" # _mongod_hack_ensure_no_arg '--some-unwanted-arg' "$@"
 # set -- "${mongodHackedArgs[@]}" # set -- "${mongodHackedArgs[@]}"
 _mongod_hack_ensure_no_arg_val() { _mongod_hack_ensure_no_arg_val() {
- local ensureNoArg="$1"; shift +        local ensureNoArg="$1"; shift 
- mongodHackedArgs=() +        mongodHackedArgs=() 
- while [ "$#" -gt 0 ]; do +        while [ "$#" -gt 0 ]; do 
- local arg="$1"; shift +                local arg="$1"; shift 
- case "$arg" in +                case "$arg" in 
- "$ensureNoArg"+                        "$ensureNoArg"
- shift # also skip the value +                                shift # also skip the value 
- continue +                                continue 
- ;; +                                ;; 
- "$ensureNoArg"=*) +                        "$ensureNoArg"=*) 
- # value is already included +                                # value is already included 
- continue +                                continue 
- ;; +                                ;; 
- esac +                esac 
- mongodHackedArgs+=( "$arg"+                mongodHackedArgs+=( "$arg"
- done+        done
 } }
 # _mongod_hack_ensure_arg_val '--some-arg' 'some-val' "$@" # _mongod_hack_ensure_arg_val '--some-arg' 'some-val' "$@"
 # set -- "${mongodHackedArgs[@]}" # set -- "${mongodHackedArgs[@]}"
 _mongod_hack_ensure_arg_val() { _mongod_hack_ensure_arg_val() {
- local ensureArg="$1"; shift +        local ensureArg="$1"; shift 
- local ensureVal="$1"; shift +        local ensureVal="$1"; shift 
- _mongod_hack_ensure_no_arg_val "$ensureArg" "$@" +        _mongod_hack_ensure_no_arg_val "$ensureArg" "$@" 
- mongodHackedArgs+=( "$ensureArg" "$ensureVal" )+        mongodHackedArgs+=( "$ensureArg" "$ensureVal" )
 } }
  
 # _js_escape 'some "string" value' # _js_escape 'some "string" value'
 _js_escape() { _js_escape() {
- jq --null-input --arg 'str' "$1" '$str'+        jq --null-input --arg 'str' "$1" '$str'
 } }
  
Ligne 289: Ligne 297:
 tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json"
 _parse_config() { _parse_config() {
- if [ -s "$tempConfigFile" ]; then +        if [ -s "$tempConfigFile" ]; then 
- return 0 +                return 0 
- fi+        fi
  
- local configPath +        local configPath 
- if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then +        if configPath="$(_mongod_hack_get_arg_val --config "$@")"; then 
- # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) +                # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) 
- # see https://docs.mongodb.com/manual/reference/configuration-options/ +                # see https://docs.mongodb.com/manual/reference/configuration-options/ 
- mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" +                mongo --norc --nodb --quiet --eval "load('/js-yaml.js'); printjson(jsyaml.load(cat($(_js_escape "$configPath"))))" > "$jsonConfigFile" 
- jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" +                jq 'del(.systemLog, .processManagement, .net, .security)' "$jsonConfigFile" > "$tempConfigFile" 
- return 0 +                return 0 
- fi+        fi
  
- return 1+        return 1
 } }
 dbPath= dbPath=
 _dbPath() { _dbPath() {
- if [ -n "$dbPath" ]; then +        if [ -n "$dbPath" ]; then 
- echo "$dbPath" +                echo "$dbPath" 
- return +                return 
- fi+        fi
  
- if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then +        if ! dbPath="$(_mongod_hack_get_arg_val --dbpath "$@")"; then 
- if _parse_config "$@"; then +                if _parse_config "$@"; then 
- dbPath="$(jq -r '.storage.dbPath // empty' "$jsonConfigFile")" +                        dbPath="$(jq -r '.storage.dbPath // empty' "$jsonConfigFile")" 
- fi +                fi 
- fi+        fi
  
- if [ -z "$dbPath" ]; then +        if [ -z "$dbPath" ]; then 
- if _mongod_hack_have_arg --configsvr "$@" || { +                if _mongod_hack_have_arg --configsvr "$@" || { 
- _parse_config "$@"+                        _parse_config "$@"
- && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")"+                        && clusterRole="$(jq -r '.sharding.clusterRole // empty' "$jsonConfigFile")"
- && [ "$clusterRole" = 'configsvr'+                        && [ "$clusterRole" = 'configsvr'
- }; then +                }; then 
- # if running as config server, then the default dbpath is /data/configdb +                        # if running as config server, then the default dbpath is /data/configdb 
- # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr +                        # https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-configsvr 
- dbPath=/data/configdb +                        dbPath=/data/configdb 
- fi +                fi 
- fi+        fi
  
- : "${dbPath:=/data/db}"+        : "${dbPath:=/data/db}"
  
- echo "$dbPath"+        echo "$dbPath"
 } }
  
 if [ "$originalArgOne" = 'mongod' ]; then if [ "$originalArgOne" = 'mongod' ]; then
- file_env 'MONGO_INITDB_ROOT_USERNAME' +        file_env 'MONGO_INITDB_ROOT_USERNAME' 
- file_env 'MONGO_INITDB_ROOT_PASSWORD' +        file_env 'MONGO_INITDB_ROOT_PASSWORD' 
- # pre-check a few factors to see if it's even worth bothering with initdb +        # pre-check a few factors to see if it's even worth bothering with initdb 
- shouldPerformInitdb= +        shouldPerformInitdb= 
- if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then +        if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then 
- # if we have a username/password, let's set "--auth" +                # if we have a username/password, let's set "--auth" 
- _mongod_hack_ensure_arg '--auth' "$@" +                _mongod_hack_ensure_arg '--auth' "$@" 
- set -- "${mongodHackedArgs[@]}" +                set -- "${mongodHackedArgs[@]}" 
- shouldPerformInitdb='true' +                shouldPerformInitdb='true' 
- elif [ "$MONGO_INITDB_ROOT_USERNAME" ] || [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then +        elif [ "$MONGO_INITDB_ROOT_USERNAME" ] || [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then 
- cat >&2 <<-'EOF' +                cat >&2 <<-'EOF' 
- error: missing 'MONGO_INITDB_ROOT_USERNAME' or 'MONGO_INITDB_ROOT_PASSWORD' +                        error: missing 'MONGO_INITDB_ROOT_USERNAME' or 'MONGO_INITDB_ROOT_PASSWORD' 
-        both must be specified for a user to be created +                               both must be specified for a user to be created 
- EOF +                EOF 
- exit 1 +                exit 1 
- fi+        fi
  
- if [ -z "$shouldPerformInitdb" ]; then +        if [ -z "$shouldPerformInitdb" ]; then 
- # if we've got any /docker-entrypoint-initdb.d/* files to parse later, we should initdb +                # if we've got any /docker-entrypoint-initdb.d/* files to parse later, we should initdb 
- for f in /docker-entrypoint-initdb.d/*; do +                for f in /docker-entrypoint-initdb.d/*; do 
- case "$f" in +                        case "$f" in 
- *.sh|*.js) # this should match the set of files we check for below +                                *.sh|*.js) # this should match the set of files we check for below 
- shouldPerformInitdb="$f" +                                        shouldPerformInitdb="$f" 
- break +                                        break 
- ;; +                                        ;; 
- esac +                        esac 
- done +                done 
- fi+        fi
  
- # check for a few known paths (to determine whether we've already initialized and should thus skip our initdb scripts) +        # check for a few known paths (to determine whether we've already initialized and should thus skip our initdb scripts) 
- if [ -n "$shouldPerformInitdb" ]; then +        if [ -n "$shouldPerformInitdb" ]; then 
- dbPath="$(_dbPath "$@")" +                dbPath="$(_dbPath "$@")" 
- for path in \ +                for path in \ 
- "$dbPath/WiredTiger"+                        "$dbPath/WiredTiger"
- "$dbPath/journal"+                        "$dbPath/journal"
- "$dbPath/local.0"+                        "$dbPath/local.0"
- "$dbPath/storage.bson"+                        "$dbPath/storage.bson"
- ; do +                ; do 
- if [ -e "$path" ]; then +                        if [ -e "$path" ]; then 
- shouldPerformInitdb= +                                shouldPerformInitdb= 
- break +                                break 
- fi +                        fi 
- done +                done 
- fi+        fi
  
- if [ -n "$shouldPerformInitdb" ]; then +        if [ -n "$shouldPerformInitdb" ]; then 
- mongodHackedArgs=( "$@"+                mongodHackedArgs=( "$@"
- if _parse_config "$@"; then +                if _parse_config "$@"; then 
- _mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}" +                        _mongod_hack_ensure_arg_val --config "$tempConfigFile" "${mongodHackedArgs[@]}" 
- fi +                fi 
- _mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}" +                _mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 "${mongodHackedArgs[@]}" 
- _mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}" +                _mongod_hack_ensure_arg_val --port 27017 "${mongodHackedArgs[@]}" 
- _mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"+                _mongod_hack_ensure_no_arg --bind_ip_all "${mongodHackedArgs[@]}"
  
- # remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control) +                # remove "--auth" and "--replSet" for our initial startup (see https://docs.mongodb.com/manual/tutorial/enable-authentication/#start-mongodb-without-access-control) 
- # https://github.com/docker-library/mongo/issues/211 +                # https://github.com/docker-library/mongo/issues/211 
- _mongod_hack_ensure_no_arg --auth "${mongodHackedArgs[@]}" +                _mongod_hack_ensure_no_arg --auth "${mongodHackedArgs[@]}" 
- if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then +                if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then 
- _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" +                        _mongod_hack_ensure_no_arg_val --replSet "${mongodHackedArgs[@]}" 
- fi+                fi
  
- sslMode="$(_mongod_hack_have_arg '--sslPEMKeyFile' "$@" && echo 'allowSSL' || echo 'disabled')" # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" +                sslMode="$(_mongod_hack_have_arg '--sslPEMKeyFile' "$@" && echo 'allowSSL' || echo 'disabled')" # "BadValue: need sslPEMKeyFile when SSL is enabled" vs "BadValue: need to enable SSL via the sslMode flag when using SSL configuration parameters" 
- _mongod_hack_ensure_arg_val --sslMode "$sslMode" "${mongodHackedArgs[@]}"+                _mongod_hack_ensure_arg_val --sslMode "$sslMode" "${mongodHackedArgs[@]}"
  
- if stat "/proc/$$/fd/1" > /dev/null && [ -w "/proc/$$/fd/1" ]; then +                if stat "/proc/$$/fd/1" > /dev/null && [ -w "/proc/$$/fd/1" ]; then 
- # https://github.com/mongodb/mongo/blob/38c0eb538d0fd390c6cb9ce9ae9894153f6e8ef5/src/mongo/db/initialize_server_global_state.cpp#L237-L251 +                        # https://github.com/mongodb/mongo/blob/38c0eb538d0fd390c6cb9ce9ae9894153f6e8ef5/src/mongo/db/initialize_server_global_state.cpp#L237-L251 
- # https://github.com/docker-library/mongo/issues/164#issuecomment-293965668 +                        # https://github.com/docker-library/mongo/issues/164#issuecomment-293965668 
- _mongod_hack_ensure_arg_val --logpath "/proc/$$/fd/1" "${mongodHackedArgs[@]}" +                        _mongod_hack_ensure_arg_val --logpath "/proc/$$/fd/1" "${mongodHackedArgs[@]}" 
- else +                else 
- initdbLogPath="$(_dbPath "$@")/docker-initdb.log" +                        initdbLogPath="$(_dbPath "$@")/docker-initdb.log" 
- echo >&2 "warning: initdb logs cannot write to '/proc/$$/fd/1', so they are in '$initdbLogPath' instead" +                        echo >&2 "warning: initdb logs cannot write to '/proc/$$/fd/1', so they are in '$initdbLogPath' instead" 
- _mongod_hack_ensure_arg_val --logpath "$initdbLogPath" "${mongodHackedArgs[@]}" +                        _mongod_hack_ensure_arg_val --logpath "$initdbLogPath" "${mongodHackedArgs[@]}" 
- fi +                fi 
- _mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"+                _mongod_hack_ensure_arg --logappend "${mongodHackedArgs[@]}"
  
- pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid" +                pidfile="${TMPDIR:-/tmp}/docker-entrypoint-temp-mongod.pid" 
- rm -f "$pidfile" +                rm -f "$pidfile" 
- _mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"+                _mongod_hack_ensure_arg_val --pidfilepath "$pidfile" "${mongodHackedArgs[@]}"
  
- "${mongodHackedArgs[@]}" --fork+                "${mongodHackedArgs[@]}" --fork
  
- mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )+                mongo=( mongo --host 127.0.0.1 --port 27017 --quiet )
  
- # check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc) +                # check to see that our "mongod" actually did start up (catches "--help", "--version", MongoDB 3.2 being silly, slow prealloc, etc) 
- # https://jira.mongodb.org/browse/SERVER-16292 +                # https://jira.mongodb.org/browse/SERVER-16292 
- tries=30 +                tries=30 
- while true; do +                while true; do 
- if ! { [ -s "$pidfile" ] && ps "$(< "$pidfile")" &> /dev/null; }; then +                        if ! { [ -s "$pidfile" ] && ps "$(< "$pidfile")" &> /dev/null; }; then 
- # bail ASAP if "mongod" isn't even running +                                # bail ASAP if "mongod" isn't even running 
- echo >&+                                echo >&
- echo >&2 "error: $originalArgOne does not appear to have stayed running -- perhaps it had an error?" +                                echo >&2 "error: $originalArgOne does not appear to have stayed running -- perhaps it had an error?" 
- echo >&+                                echo >&
- exit 1 +                                exit 1 
- fi +                        fi 
- if "${mongo[@]}" 'admin' --eval 'quit(0)' &> /dev/null; then +                        if "${mongo[@]}" 'admin' --eval 'quit(0)' &> /dev/null; then 
- # success! +                                # success! 
- break +                                break 
- fi +                        fi 
- (( tries-- )) +                        (( tries-- )) 
- if [ "$tries" -le 0 ]; then +                        if [ "$tries" -le 0 ]; then 
- echo >&+                                echo >&
- echo >&2 "error: $originalArgOne does not appear to have accepted connections quickly enough -- perhaps it had an error?" +                                echo >&2 "error: $originalArgOne does not appear to have accepted connections quickly enough -- perhaps it had an error?" 
- echo >&+                                echo >&
- exit 1 +                                exit 1 
- fi +                        fi 
- sleep 1 +                        sleep 1 
- done+                done
  
- if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then +                if [ "$MONGO_INITDB_ROOT_USERNAME" ] && [ "$MONGO_INITDB_ROOT_PASSWORD" ]; then 
- rootAuthDatabase='admin'+                        rootAuthDatabase='admin'
  
- "${mongo[@]}" "$rootAuthDatabase" <<-EOJS +                        "${mongo[@]}" "$rootAuthDatabase" <<-EOJS 
- db.createUser({ +                                db.createUser({ 
- user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"), +                                        user: $(_js_escape "$MONGO_INITDB_ROOT_USERNAME"), 
- pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"), +                                        pwd: $(_js_escape "$MONGO_INITDB_ROOT_PASSWORD"), 
- roles: [ { role: 'root', db: $(_js_escape "$rootAuthDatabase") } ] +                                        roles: [ { role: 'root', db: $(_js_escape "$rootAuthDatabase") } ] 
- }) +                                }) 
- EOJS +                        EOJS 
- fi+                fi
  
- export MONGO_INITDB_DATABASE="${MONGO_INITDB_DATABASE:-test}"+                export MONGO_INITDB_DATABASE="${MONGO_INITDB_DATABASE:-test}"
  
- echo +                echo 
- for f in /docker-entrypoint-initdb.d/*; do +                for f in /docker-entrypoint-initdb.d/*; do 
- case "$f" in +                        case "$f" in 
- *.sh) echo "$0: running $f"; . "$f" ;; +                                *.sh) echo "$0: running $f"; . "$f" ;; 
- *.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;; +                                *.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;; 
- *)    echo "$0: ignoring $f" ;; +                                *)    echo "$0: ignoring $f" ;; 
- esac +                        esac 
- echo +                        echo 
- done+                done
  
- "${mongodHackedArgs[@]}" --shutdown +                "${mongodHackedArgs[@]}" --shutdown 
- rm -f "$pidfile"+                rm -f "$pidfile"
  
- echo +                echo 
- echo 'MongoDB init process complete; ready for start up.' +                echo 'MongoDB init process complete; ready for start up.' 
- echo +                echo 
- fi+        fi
  
- # MongoDB 3.6+ defaults to localhost-only binding +        # MongoDB 3.6+ defaults to localhost-only binding 
- if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported +        if mongod --help 2>&1 | grep -q -- --bind_ip_all; then # TODO remove this conditional when 3.4 is no longer supported 
- haveBindIp= +                haveBindIp= 
- if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then +                if _mongod_hack_have_arg --bind_ip "$@" || _mongod_hack_have_arg --bind_ip_all "$@"; then 
- haveBindIp=1 +                        haveBindIp=1 
- elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then +                elif _parse_config "$@" && jq --exit-status '.net.bindIp // .net.bindIpAll' "$jsonConfigFile" > /dev/null; then 
- haveBindIp=1 +                        haveBindIp=1 
- fi +                fi 
- if [ -z "$haveBindIp" ]; then +                if [ -z "$haveBindIp" ]; then 
- # so if no "--bind_ip" is specified, let's add "--bind_ip_all" +                        # so if no "--bind_ip" is specified, let's add "--bind_ip_all" 
- set -- "$@" --bind_ip_all +                        set -- "$@" --bind_ip_all 
- fi +                fi 
- fi+        fi
  
- unset "${!MONGO_INITDB_@}"+        unset "${!MONGO_INITDB_@}"
 fi fi
  
Ligne 495: Ligne 503:
  
 exec "$@" exec "$@"
-</file>+</code>
  
 Examinons chaque commande dans le Dockerfile : Examinons chaque commande dans le Dockerfile :
Ligne 541: Ligne 549:
  wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \  wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
  export GNUPGHOME="$(mktemp -d)"; \  export GNUPGHOME="$(mktemp -d)"; \
- gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \+ gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
  gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \  gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
  command -v gpgconf && gpgconf --kill all || :; \  command -v gpgconf && gpgconf --kill all || :; \
Ligne 560: Ligne 568:
  export GNUPGHOME="$(mktemp -d)"; \  export GNUPGHOME="$(mktemp -d)"; \
  for key in $GPG_KEYS; do \  for key in $GPG_KEYS; do \
- gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \+ gpg --batch --keyserver pgp.mit.edu --recv-keys "$key"; \
  done; \  done; \
  gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg; \  gpg --batch --export $GPG_KEYS > /etc/apt/trusted.gpg.d/mongodb.gpg; \
Ligne 590: Ligne 598:
   RUN ["/bin/bash", "-c", "commande"]   RUN ["/bin/bash", "-c", "commande"]
  
-<WRAP center round important>+<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'image seulement. Cette commande ne doit pas donc être utilisée pour exécuter une commande lors du lancement du conteneur. La commande utilisée pour accomplir ce dernier est ENTRYPOINT. **Important** : La commande RUN est utilisée pour exécuter une commande passée en argument lors de la compilation de l'image seulement. Cette commande ne doit pas donc être utilisée pour exécuter une commande lors du lancement du conteneur. La commande utilisée pour accomplir ce dernier est ENTRYPOINT.
 </WRAP> </WRAP>
Ligne 641: Ligne 649:
 Il est possible d'exclure des fichiers présents dans le contexte en les mettant dans un fichier appelé **.dockerignore** placé dans le contexte. Il est possible d'exclure des fichiers présents dans le contexte en les mettant dans un fichier appelé **.dockerignore** placé dans le contexte.
  
-<WRAP center round important>+<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'utilisation de la commande ADD, si le fichier source est une archive de type TAR, son contenu sera désarchivé et copier vers la destination tandis que si le fichier source est référencé par un URL, le contenu sera téléchargé puis déposé dans la destination. **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'utilisation de la commande ADD, si le fichier source est une archive de type TAR, son contenu sera désarchivé et copier vers la destination tandis que si le fichier source est référencé par un URL, le contenu sera téléchargé puis déposé dans la destination.
 </WRAP> </WRAP>
Ligne 697: Ligne 705:
 Ce fichier finit par "$@" qui indique que si aucune condition n'ait été remplie, la commande est exécutée avec la valeur passée en argument. Ce fichier finit par "$@" qui indique que si aucune condition n'ait été remplie, la commande est exécutée avec la valeur passée en argument.
  
-<WRAP center round important>+<WRAP center round important 50%>
 **Important** - Notez que la compilation d'une image se fait à l'intérieur d'un **contexte**. Le **contexte** est le répertoire de build. Dernièrement, notez qu'il peut y avoir plusieurs ENTRYPOINT dans le fichier Dockerfile mais uniquement le dernier est pris en compte. **Important** - Notez que la compilation d'une image se fait à l'intérieur d'un **contexte**. Le **contexte** est le répertoire de build. Dernièrement, notez qu'il peut y avoir plusieurs ENTRYPOINT dans le fichier Dockerfile mais uniquement le dernier est pris en compte.
 </WRAP> </WRAP>
Ligne 734: Ligne 742:
  
 <code> <code>
-root@debian9:~/mongodb# docker build .+root@debian11:~/mongodb# docker build . 
 +[+] Building 56.9s (15/15) FINISHED                                                                                                                                 docker:default 
 + => [internal] load .dockerignore                                                                                                                                             0.0s 
 + => => transferring context: 2B                                                                                                                                               0.0s 
 + => [internal] load build definition from Dockerfile                                                                                                                          0.1s 
 + => => transferring dockerfile: 3.55kB                                                                                                                                        0.0s 
 + => [internal] load metadata for docker.io/library/ubuntu:bionic                                                                                                              0.3s 
 + => [internal] load build context                                                                                                                                             0.0s 
 + => => transferring context: 42B                                                                                                                                              0.0s 
 + => [ 1/10] FROM docker.io/library/ubuntu:bionic@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98                                                      0.0s 
 + => CACHED [ 2/10] RUN groupadd -r mongodb && useradd -r -g mongodb mongodb                                                                                                   0.0s 
 + => CACHED [ 3/10] RUN set -eux;  apt-get update;  apt-get install -y --no-install-recommends   ca-certificates   jq   numactl  ;  if ! command -v ps > /dev/null; then   ap  0.0s 
 + => [ 4/10] 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-r  20.6s 
 + => [ 5/10] RUN mkdir /docker-entrypoint-initdb.d                                                                                                                             0.5s 
 + => [ 6/10] RUN set -ex;  export GNUPGHOME="$(mktemp -d)";  for key in E162F504A20CDF15827F718D4B7C549A058F8B6B; do   gpg --batch --keyserver pgp.mit.edu --recv-keys "$key  10.4s  
 + => [ 7/10] RUN echo "deb http://$MONGO_REPO/apt/ubuntu bionic/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR multiverse" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-unstable}  0.5s  
 + => [ 8/10] RUN set -x  && apt-get update  && apt-get install -y   mongodb-org-unstable=4.1.9   mongodb-org-unstable-server=4.1.9   mongodb-org-unstable-shell=4.1.9   mong  21.1s  
 + => [ 9/10] RUN mkdir -p /data/db /data/configdb  && chown -R mongodb:mongodb /data/db /data/configdb                                                                         0.5s  
 + => [10/10] COPY docker-entrypoint.sh /usr/local/bin/                                                                                                                         0.1s  
 + => exporting to image                                                                                                                                                        2.6s  
 + => => exporting layers                                                                                                                                                       2.6s  
 + => => writing image sha256:72fad0b7e0c2206f31a12b7d49f0812c0a594a51e17a8c0e36687f5f626bc735                                                                                  0.0s
 </code> </code>
  
Ligne 740: Ligne 769:
  
 <code> <code>
-root@debian9:~/mongodb# docker images +root@debian11:~/mongodb# docker images                                                                                                                                              
-REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE +REPOSITORY           TAG       IMAGE ID       CREATED              SIZE 
-<none>              <none>              3bf216d921d6        About a minute ago   96.2MB +<none>               <none>    72fad0b7e0c2   About a minute ago   352MB 
-i2tch/mongodb       latest              eca7835d4fe6        11 minutes ago       1.03GB +ittraining/mongodb   latest    fb3c6d5d186a   7 hours ago          1.11GB 
-nginx               latest              2bcb04bdb83f        13 days ago          109MB +ubuntu               latest    b6548eacb063   days ago           77.8MB 
-centos              latest              9f38484d220f        3 weeks ago          202MB +nginx                latest    a6bd71f48f68   weeks ago          187MB 
-ubuntu              bionic              94e814e2efa8        4 weeks ago          88.9MB +hello-world          latest    9c7a54a9a43c   months ago         13.3kB 
-ubuntu              latest              94e814e2efa8        4 weeks ago          88.9MB +centos               latest    5d0da3dc9764   2 years ago          231MB
-hello-world         latest              fce289e99eb9        3 months ago         1.84kB+
 </code> </code>
  
Ligne 754: Ligne 782:
  
 <code> <code>
-root@debian9:~/mongodb# docker tag 3bf2 i2tch/mongodb1 +root@debian11:~/mongodb# docker tag 72f i2tch/mongodb1 
-root@debian9:~/mongodb# docker images + 
-REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE +root@debian11:~/mongodb# docker images 
-i2tch/mongodb1      latest              3bf216d921d6        2 minutes ago       96.2MB +REPOSITORY           TAG       IMAGE ID       CREATED         SIZE 
-i2tch/mongodb       latest              eca7835d4fe6        11 minutes ago      1.03GB +i2tch/mongodb1       latest    72fad0b7e0c2   2 minutes ago   352MB 
-nginx               latest              2bcb04bdb83f        13 days ago         109MB +ittraining/mongodb   latest    fb3c6d5d186a   7 hours ago     1.11GB 
-centos              latest              9f38484d220f        3 weeks ago         202MB +ubuntu               latest    b6548eacb063   days ago      77.8MB 
-ubuntu              bionic              94e814e2efa8        4 weeks ago         88.9MB +nginx                latest    a6bd71f48f68   weeks ago     187MB 
-ubuntu              latest              94e814e2efa8        4 weeks ago         88.9MB +hello-world          latest    9c7a54a9a43c   months ago    13.3kB 
-hello-world         latest              fce289e99eb9        3 months ago        1.84kB+centos               latest    5d0da3dc9764   2 years ago     231MB
 </code> </code>
  
Ligne 769: Ligne 797:
  
 <code> <code>
-root@debian9:~/mongodb# docker run -d --name mongo1 i2tch/mongodb1 +root@debian11:~/mongodb# docker run -d --name mongo1 i2tch/mongodb1 
-bdb4bc0f81de8b5821f20d8609b9640abaaae7b4a7577c42b78d4bd34617d211 +3c578ea2a0428a07b60dac3b63d806351dffa2bb05224bcf7d12f1189766f38e 
-docker: Error response from daemon: oci runtime errorcontainer_linux.go:262starting container process caused "exec: \"docker-entrypoint.sh\": executable file not found in $PATH"+docker: Error response from daemon: failed to create task for containerfailed to create shim taskOCI runtime create failed: runc create failedunable to start container processexec: "docker-entrypoint.sh": executable file not found in $PATH: unknown. 
-root@debian9:~/mongodb# ls -l+ 
 +root@debian11:~/mongodb# ls -l
 total 16 total 16
--rw-r--r-- 1 root root 10971 avril  9 13:56 docker-entrypoint.sh +-rw-r--r-- 1 root root 10971 Dec 10 16:57 docker-entrypoint.sh 
--rw-r--r-- 1 root root  3542 avril  9 13:55 Dockerfile+-rw-r--r-- 1 root root  3514 Dec 10 17:09 Dockerfile
 </code> </code>
  
-<WRAP center round important> +<WRAP center round important 50%
-**Important** - Notez que le fichier docker-entrypoint.sh n'était pas exécutable !+**Important** - Notez que le fichier docker-entrypoint.sh n'est pas exécutable !
 </WRAP> </WRAP>
  
Ligne 785: Ligne 814:
  
 <code> <code>
-root@debian9:~/mongodb# docker rm mongo1+root@debian11:~/mongodb# docker rm mongo1
 mongo1 mongo1
-root@debian9:~/mongodb# chmod +x docker-entrypoint.sh + 
-root@debian9:~/mongodb# docker build . +root@debian11:~/mongodb# chmod +x docker-entrypoint.sh 
-Sending build context to Docker daemon   16.9kB + 
-Step 1/22 : FROM ubuntu:bionic +root@debian11:~/mongodb# docker build . 
- ---94e814e2efa8 +[+] Building 0.8s (15/15) FINISHED                                                                                                                                  docker:default 
-Step 2/22 : RUN groupadd -r mongodb && useradd -r -g mongodb mongodb + => [internal] load build definition from Dockerfile                                                                                                                          0.1s 
- ---Using cache + => => transferring dockerfile: 3.55kB                                                                                                                                        0.0s 
- ---> f40ac453fa97 + => [internal] load .dockerignore                                                                                                                                             0.1s 
-Step 3/22 : 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 /var/lib/apt/lists/* + => => transferring context: 2B                                                                                                                                               0.0s 
- ---> Using cache + => [internal] load metadata for docker.io/library/ubuntu:bionic                                                                                                              0.3s 
- ---> adc57da1b19f + => [ 1/10] FROM docker.io/library/ubuntu:bionic@sha256:152dc042452c496007f07ca9127571cb9c29697f42acbfad72324b2bb2e43c98                                                      0.0s 
-Step 4/22 : ENV GOSU_VERSION 1.11 + =[internal] load build context                                                                                                                                             0.0s 
- ---> Using cache + => => transferring context: 11.02kB                                                                                                                                          0.0s 
- ---> 038e7de870b7 + => CACHED [ 2/10] RUN groupadd -r mongodb && useradd -r -g mongodb mongodb                                                                                                   0.0s 
-Step 5/22 ENV JSYAML_VERSION 3.13.0 + =CACHED [ 3/10] RUN set -eux;  apt-get update;  apt-get install -y --no-install-recommends   ca-certificates   jq   numactl   if ! command -v ps > /dev/null; then   ap  0.0s 
- ---> Using cache + => CACHED [ 4/10] RUN set -ex;   apt-get update;  apt-get install -y --no-install-recommends   wget   if ! command -v gpg > /dev/null; then   apt-get install ---no-ins  0.0s 
- ---> 3bf216d921d6 + => CACHED [ 5/10] RUN mkdir /docker-entrypoint-initdb.d                                                                                                                      0.0s 
-... + => CACHED [ 6/10] RUN set -ex;  export GNUPGHOME="$(mktemp -d)";  for key in E162F504A20CDF15827F718D4B7C549A058F8B6B; do   gpg --batch --keyserver pgp.mit.edu --recv-keys  0.0s 
-Removing intermediate container a98ae692fe1f + => CACHED [ 7/10] RUN echo "deb http://$MONGO_REPO/apt/ubuntu bionic/${MONGO_PACKAGE%-unstable}/$MONGO_MAJOR multiverse" | tee "/etc/apt/sources.list.d/${MONGO_PACKAGE%-un  0.0s 
- ---> 04c2e98927c3 + => CACHED [ 8/10] RUN set -x  && apt-get update  && apt-get install -y   mongodb-org-unstable=4.1.9   mongodb-org-unstable-server=4.1.9   mongodb-org-unstable-shell=4.1.9   0.0s 
-Step 17/22 : RUN mkdir -p /data/db /data/configdb  && chown -R mongodb:mongodb /data/db /data/configdb + => CACHED [ 9/10] RUN mkdir -p /data/db /data/configdb  && chown -R mongodb:mongodb /data/db /data/configdb                                                                  0.0s 
- ---Running in d0f5bee34571 + =[10/10] COPY docker-entrypoint.sh /usr/local/bin/                                                                                                                         0.2s 
-Removing intermediate container d0f5bee34571 + =exporting to image                                                                                                                                                        0.1s 
- ---> d5b95e9e63e1 + ==exporting layers                                                                                                                                                       0.1s 
-Step 18/22 : VOLUME /data/db /data/configdb + ==writing image sha256:56e5b1fb4284e2474392238ee5f91a5d27d9a4a43fa15f655136ae0283d269c2                                                                                  0.0s
- ---> Running in c7626528a9b9 +
-Removing intermediate container c7626528a9b9 +
- ---> 4250613adf6a +
-Step 19/22 : COPY docker-entrypoint.sh /usr/local/bin/ +
- ---eedfd53da0f8 +
-Step 20/22 : ENTRYPOINT ["docker-entrypoint.sh"] +
- ---Running in eff53d0213d1 +
-Removing intermediate container eff53d0213d1 +
- ---716abf2faa87 +
-Step 21/22 : EXPOSE 27017 +
- ---Running in 5139fcf19d7f +
-Removing intermediate container 5139fcf19d7f +
- ---fc5896e08fd6 +
-Step 22/22 CMD ["mongod"+
- ---> Running in 458d6f15cdf2 +
-Removing intermediate container 458d6f15cdf2 +
- ---> 12e00099ca8d +
-Successfully built 12e00099ca8d +
-root@debian9:~/mongodb# +
 </code> </code>
  
-<WRAP center round important> +<WRAP center round important 50%
-**Important** - Notez ici les lignes **Using cache**. Il est cependant possible de ne pas utiliser le cache en stipulant **--no-cache**. Notez aussi l'utilisation de conteneurs temporaires par étape nouvelle avec un commit vers une image et une suppression dudit conteneur. Dernièrement, notez que la compilation d'une image se fait à l'intérieur d'un **contexte**. Le **contexte** est le répertoire de build. **Attention** : tous les fichiers dans le contexte sont inclus dans l'image finale, même ceux qui sont inutiles.+**Important** - Notez ici les lignes **CACHED**. Il est cependant possible de ne pas utiliser le cache en stipulant **--no-cache**. Notez aussi l'utilisation de conteneurs temporaires par étape nouvelle avec un commit vers une image et une suppression dudit conteneur. Dernièrement, notez que la compilation d'une image se fait à l'intérieur d'un **contexte**. Le **contexte** est le répertoire de build. **Attention** : tous les fichiers dans le contexte sont inclus dans l'image finale, même ceux qui sont inutiles.
 </WRAP> </WRAP>
  
Ligne 840: Ligne 850:
  
 <code> <code>
-root@debian9:~/mongodb# docker images +root@debian11:~/mongodb# docker images 
-REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE +REPOSITORY           TAG       IMAGE ID       CREATED              SIZE 
-<none>              <none>              12e00099ca8d        42 seconds ago      377MB +<none>               <none>    56e5b1fb4284   About a minute ago   352MB 
-i2tch/mongodb1      latest              3bf216d921d6        10 minutes ago      96.2MB +i2tch/mongodb1       latest    72fad0b7e0c2   minutes ago        352MB 
-i2tch/mongodb       latest              eca7835d4fe6        19 minutes ago      1.03GB +ittraining/mongodb   latest    fb3c6d5d186a   7 hours ago          1.11GB 
-nginx               latest              2bcb04bdb83f        13 days ago         109MB +ubuntu               latest    b6548eacb063   days ago           77.8MB 
-centos              latest              9f38484d220f        3 weeks ago         202MB +nginx                latest    a6bd71f48f68   weeks ago          187MB 
-ubuntu              bionic              94e814e2efa8        4 weeks ago         88.9MB +hello-world          latest    9c7a54a9a43c   months ago         13.3kB 
-ubuntu              latest              94e814e2efa8        4 weeks ago         88.9MB +centos               latest    5d0da3dc9764   2 years ago          231MB 
-hello-world         latest              fce289e99eb9        3 months ago        1.84kB + 
-root@debian9:~/mongodb# docker tag 12e0 i2tch/mongodb2 +root@debian11:~/mongodb# docker tag 56e i2tch/mongodb2 
-root@debian9:~/mongodb# docker images + 
-REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE +root@debian11:~/mongodb# docker images 
-i2tch/mongodb2      latest              12e00099ca8d        About a minute ago   377MB +REPOSITORY           TAG       IMAGE ID       CREATED              SIZE 
-i2tch/mongodb1      latest              3bf216d921d6        11 minutes ago       96.2MB +i2tch/mongodb2       latest    56e5b1fb4284   About a minute ago   352MB 
-i2tch/mongodb       latest              eca7835d4fe6        20 minutes ago       1.03GB +i2tch/mongodb1       latest    72fad0b7e0c2   minutes ago        352MB 
-nginx               latest              2bcb04bdb83f        13 days ago          109MB +ittraining/mongodb   latest    fb3c6d5d186a   7 hours ago          1.11GB 
-centos              latest              9f38484d220f        3 weeks ago          202MB +ubuntu               latest    b6548eacb063   days ago           77.8MB 
-ubuntu              bionic              94e814e2efa8        4 weeks ago          88.9MB +nginx                latest    a6bd71f48f68   weeks ago          187MB 
-ubuntu              latest              94e814e2efa8        4 weeks ago          88.9MB +hello-world          latest    9c7a54a9a43c   months ago         13.3kB 
-hello-world         latest              fce289e99eb9        3 months ago         1.84kB+centos               latest    5d0da3dc9764   2 years ago          231MB
 </code> </code>
  
Ligne 866: Ligne 876:
  
 <code> <code>
-root@debian9:~/mongodb# docker run -d --name mongo2 i2tch/mongodb2 +root@debian11:~/mongodb# docker run -d --name mongo2 i2tch/mongodb2 
-e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a+880733c6bdc33a9a8fa6ae171e977cf745ea9a1b9cfc914992a2d0d3f8cd9d39
 </code> </code>
  
Ligne 873: Ligne 883:
  
 <code> <code>
-root@debian9:~/mongodb# docker ps +root@debian11:~/mongodb# docker ps 
-CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS                               NAMES 
-e91a055283f4        i2tch/mongodb2      "docker-entrypoint.s…"   28 seconds ago      Up 27 seconds       27017/tcp            mongo2 +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   15 seconds ago   Up 13 seconds   27017/tcp                           mongo2 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   21 minutes ago      Up 19 minutes                            mongo +885f75b6aa57   ittraining/mongodb   "bash"                   7 hours ago      Up 7 hours                                          mongo 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago   Up About an hour    0.0.0.0:81->80/tcp   suspicious_sanderson+04d910a3c93d   nginx                "/docker-entrypoint.…"   7 hours ago      Up 7 hours      0.0.0.0:81->80/tcp, :::81->80/tcp   quirky_moore
 </code> </code>
  
Ligne 883: Ligne 893:
  
 <code> <code>
-root@debian9:~/mongodb# docker inspect mongo2 | grep IP+root@debian11:~/mongodb# docker inspect mongo2 | grep IP
             "LinkLocalIPv6Address": "",             "LinkLocalIPv6Address": "",
             "LinkLocalIPv6PrefixLen": 0,             "LinkLocalIPv6PrefixLen": 0,
Ligne 899: Ligne 909:
                     "GlobalIPv6Address": "",                     "GlobalIPv6Address": "",
                     "GlobalIPv6PrefixLen": 0,                     "GlobalIPv6PrefixLen": 0,
-root@debian9:~/mongodb# + 
-root@debian9:~/mongodb# mongo --host 172.17.0.4 +root@debian11:~/mongodb# mongo --host 172.17.0.4 
-MongoDB shell version v4.0.8+MongoDB shell version v4.0.28
 connecting to: mongodb://172.17.0.4:27017/?gssapiServiceName=mongodb connecting to: mongodb://172.17.0.4:27017/?gssapiServiceName=mongodb
-Implicit session: session { "id" : UUID("3feff8c0-5460-473b-b036-4aee64a314f7") }+Implicit session: session { "id" : UUID("057eacfe-5b02-4653-9b20-a2a2044cbe6a") }
 MongoDB server version: 4.1.9 MongoDB server version: 4.1.9
 WARNING: shell and server versions do not match WARNING: shell and server versions do not match
 Server has startup warnings:  Server has startup warnings: 
-2019-04-09T17:50:12.635+0000 I STORAGE  [initandlisten]  +2023-12-10T16:16:13.395+0000 I STORAGE  [initandlisten]  
-2019-04-09T17:50:12.636+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine +2023-12-10T16:16:13.395+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 
-2019-04-09T17:50:12.636+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem +2023-12-10T16:16:13.395+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem 
-2019-04-09T17:50:13.458+0000 I CONTROL  [initandlisten]  +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten]  
-2019-04-09T17:50:13.459+0000 I CONTROL  [initandlisten] ** NOTE: This is a development version (4.1.9) of MongoDB. +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten] ** NOTE: This is a development version (4.1.9) of MongoDB. 
-2019-04-09T17:50:13.459+0000 I CONTROL  [initandlisten] **       Not recommended for production. +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten] **       Not recommended for production. 
-2019-04-09T17:50:13.459+0000 I CONTROL  [initandlisten]  +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten]  
-2019-04-09T17:50:13.459+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database. +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database. 
-2019-04-09T17:50:13.459+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted. +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted. 
-2019-04-09T17:50:13.460+0000 I CONTROL  [initandlisten] +2023-12-10T16:16:14.255+0000 I CONTROL  [initandlisten]  
 +2023-12-10T16:16:14.256+0000 I CONTROL  [initandlisten]  
 +2023-12-10T16:16:14.256+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'
 +2023-12-10T16:16:14.256+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never' 
 +2023-12-10T16:16:14.256+0000 I CONTROL  [initandlisten] 
 --- ---
 Enable MongoDB's free cloud-based monitoring service, which will then receive and display Enable MongoDB's free cloud-based monitoring service, which will then receive and display
Ligne 931: Ligne 945:
 > exit > exit
 bye bye
-root@debian9:~/mongodb# +root@debian11:~/mongodb#
-</code> +
- +
-Notez que lors de la compilation de l'image finale, une image a été créée lors de chaque instruction dans le fichier Dockerfile sauf en cas d'utilisation d'une image en cache : +
- +
-<code> +
-root@debian9:~/mongodb# docker images -a +
-REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE +
-i2tch/mongodb2      latest              12e00099ca8d        5 minutes ago       377MB +
-<none>              <none>              d5b95e9e63e1        5 minutes ago       377MB +
-<none>              <none>              4250613adf6a        5 minutes ago       377MB +
-<none>              <none>              eedfd53da0f8        5 minutes ago       377MB +
-<none>              <none>              04c2e98927c3        5 minutes ago       377MB +
-<none>              <none>              c6eae79e3d22        7 minutes ago       110MB +
-<none>              <none>              c205179d538c        7 minutes ago       110MB +
-<none>              <none>              b70835bebe35        7 minutes ago       110MB +
-<none>              <none>              5b2827910929        7 minutes ago       110MB +
-<none>              <none>              5b1f6df94d98        7 minutes ago       110MB +
-<none>              <none>              a950a5d04b68        7 minutes ago       110MB +
-<none>              <none>              c183cfecc5f0        7 minutes ago       110MB +
-<none>              <none>              aadb5806f1b8        8 minutes ago       110MB +
-<none>              <none>              8d538d38407e        8 minutes ago       110MB +
-<none>              <none>              32d59bf23987        8 minutes ago       110MB +
-i2tch/mongodb1      latest              3bf216d921d6        15 minutes ago      96.2MB +
-<none>              <none>              038e7de870b7        15 minutes ago      96.2MB +
-<none>              <none>              adc57da1b19f        15 minutes ago      96.2MB +
-<none>              <none>              f40ac453fa97        15 minutes ago      89.3MB +
-i2tch/mongodb       latest              eca7835d4fe6        24 minutes ago      1.03GB +
-<none>              <none>              620057baa411        27 minutes ago      816MB +
-<none>              <none>              67afc80e1424        33 minutes ago      816MB +
-nginx               latest              2bcb04bdb83f        13 days ago         109MB +
-centos              latest              9f38484d220f        3 weeks ago         202MB +
-ubuntu              bionic              94e814e2efa8        4 weeks ago         88.9MB +
-ubuntu              latest              94e814e2efa8        4 weeks ago         88.9MB +
-hello-world         latest              fce289e99eb9        3 months ago        1.84kB+
 </code> </code>
  
Ligne 975: Ligne 955:
  
 <code> <code>
-root@debian9:~/mongodb# mkdir ~/myDocker +root@debian11:~/mongodb# mkdir ~/myDocker 
-root@debian9:~/mongodb# cd ~/myDocker +root@debian11:~/mongodb# cd ~/myDocker 
-root@debian9:~/myDocker# +root@debian11:~/myDocker# 
 </code> </code>
  
Ligne 983: Ligne 963:
  
 <code> <code>
-root@debian9:~/myDocker# vi myEntrypoint.sh +root@debian11:~/myDocker# vi myEntrypoint.sh 
-root@debian9:~/myDocker# cat myEntrypoint.sh + 
 +root@debian11:~/myDocker# cat myEntrypoint.sh
 #!/bin/bash #!/bin/bash
 if [ -z "$myVariable" ]; then if [ -z "$myVariable" ]; then
- echo "La variable myVariable doit être renseignée+        echo "The variable myVariable must have a value
- return 1+        return 1
 fi fi
  
 while true; while true;
 do do
- echo $1 \($(date +%H:%M:%S)\); +        echo $1 \($(date +%H:%M:%S)\); 
- sleep "$myVariable";+        sleep "$myVariable";
 done done
 </code> </code>
Ligne 1001: Ligne 982:
  
 <code> <code>
-root@debian9:~/myDocker# myVariable=3 . ./myEntrypoint.sh salut +root@debian11:~/myDocker# myVariable=3 . ./myEntrypoint.sh Hello! 
-salut (20:04:39+Hello! (18:01:54
-salut (20:04:42+Hello! (18:01:57
-salut (20:04:45+Hello! (18:02:00
-salut (20:04:48+Hello! (18:02:03
-salut (20:04:51)+Hello! (18:02:06)
 ^C ^C
-root@debian9:~/myDocker# +root@debian11:~/myDocker# 
 </code> </code>
  
Ligne 1014: Ligne 995:
  
 <code> <code>
-root@debian9:~/myDocker# chmod u+x myEntrypoint.sh +root@debian11:~/myDocker# chmod u+x myEntrypoint.sh 
 </code> </code>
  
Ligne 1020: Ligne 1001:
  
 <code> <code>
-root@debian9:~/myDocker# vi Dockerfile +root@debian11:~/myDocker# vi Dockerfile 
-root@debian9:~/myDocker# cat Dockerfile+ 
 +root@debian11:~/myDocker# cat Dockerfile
 FROM centos:latest FROM centos:latest
-MAINTAINER i2tch "infos@i2tch.eu"+MAINTAINER Team IT Training "infos@ittraining.team"
 COPY myEntrypoint.sh /entrypoint.sh COPY myEntrypoint.sh /entrypoint.sh
 ENV myVariable 3 ENV myVariable 3
Ligne 1033: Ligne 1015:
  
 <code> <code>
-root@debian9:~/myDocker# docker build -t i2tch/mydocker . +root@debian11:~/myDocker# docker build -t i2tch/mydocker . 
-Sending build context to Docker daemon  3.072kB +[+] Building 0.8s (7/7) FINISHED                                                                                                                                    docker:default 
-Step 1/FROM centos:latest + =[internal] load .dockerignore                                                                                                                                             0.2s 
- ---9f38484d220f + => => transferring context2B                                                                                                                                               0.0s 
-Step 2/6 MAINTAINER i2tch "infos@i2tch.eu" + =[internal] load build definition from Dockerfile                                                                                                                          0.1s 
- ---Running in 02c700ed04da + ==> transferring dockerfile211B                                                                                                                                          0.0s 
-Removing intermediate container 02c700ed04da + =[internal] load metadata for docker.io/library/centos:latest                                                                                                              0.0s 
- ---4274107d52e2 + =[internal] load build context                                                                                                                                             0.1s 
-Step 3/6 COPY myEntrypoint.sh /entrypoint.sh + ==> transferring context: 224B                                                                                                                                             0.0s 
- ---7a3923372768 + => [1/2] FROM docker.io/library/centos:latest                                                                                                                                0.1s 
-Step 4/ENV myVariable 3 + => [2/2] COPY myEntrypoint.sh /entrypoint.sh                                                                                                                                 0.2s 
- ---Running in 3288bf6291ad + =exporting to image                                                                                                                                                        0.1s 
-Removing intermediate container 3288bf6291ad + => =exporting layers                                                                                                                                                       0.1s 
- ---3edb630c1511 + => => writing image sha256:c5a41438d278439fac2cd65d53d87cabc5c771dd9b99be1913ce049024eba961                                                                                  0.0s 
-Step 5/ENTRYPOINT ["/entrypoint.sh"] + ==naming to docker.io/i2tch/mydocker                                                                                                                                     0.0s
- ---Running in 8dcba2c41520 +
-Removing intermediate container 8dcba2c41520 +
- ---11962052539c +
-Step 6/6 CMD ["mycommand"] +
- ---Running in f891fbcfaad0 +
-Removing intermediate container f891fbcfaad0 +
- ---7925ba23abb2 +
-Successfully built 7925ba23abb2 +
-Successfully tagged i2tch/mydocker:latest+
 </code> </code>
  
Ligne 1062: Ligne 1035:
  
 <code> <code>
-root@debian9:~/myDocker# docker run -it --name myDocker i2tch/mydocker +root@debian11:~/myDocker# docker run -it --name myDocker i2tch/mydocker 
-mycommand (18:07:12+mycommand (17:05:57
-mycommand (18:07:15+mycommand (17:06:00
-mycommand (18:07:18) +mycommand (17:06:03
-mycommand (18:07:21+^Cmycommand (17:06:06
-^Cmycommand (18:07:22+mycommand (17:06:09
-mycommand (18:07:25+mycommand (17:06:12)
-mycommand (18:07:28)+
 ^P^Q ^P^Q
-root@debian9:~/myDocker#+root@debian11:~/myDocker#
 </code> </code>
 +
 +<WRAP center round important 50%>
 +**Important** - Notez que **^C** n'a aucun effet. Pour se détacher du conteneur il convient d'utiliser **^P^Q**.
 +</WRAP>
  
 Constatez que le conteneur est toujours en cours de fonctionnement : Constatez que le conteneur est toujours en cours de fonctionnement :
  
 <code> <code>
-root@debian9:~/myDocker# docker ps +root@debian11:~/myDocker# docker ps 
-CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                NAMES +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS                               NAMES 
-140ecfdd80b7        i2tch/mydocker      "/entrypoint.sh myco…"   About a minute ago   Up About a minute                        myDocker +97fe360bb1d6   i2tch/mydocker       "/entrypoint.sh myco…"   4 minutes ago    Up 4 minutes                                        myDocker 
-b3380889eb75        i2tch/mongodb2      "docker-entrypoint.s…"   minutes ago        Up minutes        27017/tcp            mongo2 +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   54 minutes ago   Up 54 minutes   27017/tcp                           mongo2 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   38 minutes ago       Up 36 minutes                            mongo +885f75b6aa57   ittraining/mongodb   "bash"                   8 hours ago      Up 8 hours                                          mongo 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago    Up About an hour    0.0.0.0:81->80/tcp   suspicious_sanderson +04d910a3c93d   nginx                "/docker-entrypoint.…"   8 hours ago      Up 8 hours      0.0.0.0:81->80/tcp:::81->80/tcp   quirky_moore 
-root@debian9:~/myDocker# + 
-root@debian9:~/myDocker# docker logs myDocker | tail +root@debian11:~/myDocker# docker logs myDocker | tail 
-mycommand (18:08:25+mycommand (17:10:30
-mycommand (18:08:28+mycommand (17:10:33
-mycommand (18:08:31+mycommand (17:10:36
-mycommand (18:08:34+mycommand (17:10:39
-mycommand (18:08:37+mycommand (17:10:42
-mycommand (18:08:40+mycommand (17:10:45
-mycommand (18:08:43+mycommand (17:10:48
-mycommand (18:08:46+mycommand (17:10:51
-mycommand (18:08:49+mycommand (17:10:54
-mycommand (18:08:52)+mycommand (17:10:57)
 </code> </code>
  
Ligne 1100: Ligne 1076:
  
 <code> <code>
-root@debian9:~/myDocker# docker stop -t 1 myDocker+root@debian11:~/myDocker# docker stop -t 1 myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker ps + 
-CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES +root@debian11:~/myDocker# docker ps 
-b3380889eb75        i2tch/mongodb2      "docker-entrypoint.s…"   minutes ago       Up minutes        27017/tcp            mongo2 +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS                               NAMES 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   40 minutes ago      Up 38 minutes                            mongo +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   55 minutes ago   Up 55 minutes   27017/tcp                           mongo2 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago   Up About an hour    0.0.0.0:81->80/tcp   suspicious_sanderson+885f75b6aa57   ittraining/mongodb   "bash"                   8 hours ago      Up 8 hours                                          mongo 
 +04d910a3c93d   nginx                "/docker-entrypoint.…"   8 hours ago      Up 8 hours      0.0.0.0:81->80/tcp, :::81->80/tcp   quirky_moore
 </code> </code>
  
Ligne 1112: Ligne 1089:
  
 <code> <code>
-root@debian9:~/myDocker# docker start myDocker+root@debian11:~/myDocker# docker start myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker ps + 
-CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES +root@debian11:~/myDocker# docker ps 
-140ecfdd80b7        i2tch/mydocker      "/entrypoint.sh myco…"   minutes ago       Up 10 seconds                            myDocker +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS          PORTS                               NAMES 
-b3380889eb75        i2tch/mongodb2      "docker-entrypoint.s…"   10 minutes ago      Up 10 minutes       27017/tcp            mongo2 +97fe360bb1d6   i2tch/mydocker       "/entrypoint.sh myco…"   minutes ago    Up seconds                                        myDocker 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   40 minutes ago      Up 38 minutes                            mongo +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   56 minutes ago   Up 56 minutes   27017/tcp                           mongo2 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago   Up About an hour    0.0.0.0:81->80/tcp   suspicious_sanderson+885f75b6aa57   ittraining/mongodb   "bash"                   8 hours ago      Up 8 hours                                          mongo 
 +04d910a3c93d   nginx                "/docker-entrypoint.…"   8 hours ago      Up 8 hours      0.0.0.0:81->80/tcp, :::81->80/tcp   quirky_moore
 </code> </code>
  
Ligne 1125: Ligne 1103:
  
 <code> <code>
-root@debian9:~/myDocker# docker pause myDocker+root@debian11:~/myDocker# docker pause myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker ps + 
-CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS                NAMES +root@debian11:~/myDocker# docker ps 
-140ecfdd80b7        i2tch/mydocker      "/entrypoint.sh myco…"   minutes ago       Up 51 seconds (Paused)                        myDocker +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS                   PORTS                               NAMES 
-b3380889eb75        i2tch/mongodb2      "docker-entrypoint.s…"   10 minutes ago      Up 10 minutes            27017/tcp            mongo2 +97fe360bb1d6   i2tch/mydocker       "/entrypoint.sh myco…"   minutes ago    Up 55 seconds (Paused)                                       myDocker 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   41 minutes ago      Up 39 minutes                                 mongo +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   56 minutes ago   Up 56 minutes            27017/tcp                           mongo2 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago   Up About an hour         0.0.0.0:81->80/tcp   suspicious_sanderson+885f75b6aa57   ittraining/mongodb   "bash"                   8 hours ago      Up 8 hours                                                   mongo 
 +04d910a3c93d   nginx                "/docker-entrypoint.…"   8 hours ago      Up 8 hours               0.0.0.0:81->80/tcp, :::81->80/tcp   quirky_moore
 </code> </code>
  
Ligne 1138: Ligne 1117:
  
 <code> <code>
-root@debian9:~/myDocker# docker unpause myDocker+root@debian11:~/myDocker# docker unpause myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker ps + 
-CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES +root@debian11:~/myDocker# docker ps 
-140ecfdd80b7        i2tch/mydocker      "/entrypoint.sh myco…"   minutes ago       Up About a minute                        myDocker +CONTAINER ID   IMAGE                COMMAND                  CREATED          STATUS              PORTS                               NAMES 
-b3380889eb75        i2tch/mongodb2      "docker-entrypoint.s…"   11 minutes ago      Up 11 minutes       27017/tcp            mongo2 +97fe360bb1d6   i2tch/mydocker       "/entrypoint.sh myco…"   minutes ago    Up About a minute                                       myDocker 
-d2ddb4f8ca8a        i2tch/mongodb       "bash"                   42 minutes ago      Up 40 minutes                            mongo +880733c6bdc3   i2tch/mongodb2       "docker-entrypoint.s…"   57 minutes ago   Up 57 minutes       27017/tcp                           mongo2 
-c080793965de        nginx               "nginx -g 'daemon of…"   About an hour ago   Up About an hour    0.0.0.0:81->80/tcp   suspicious_sanderson+885f75b6aa57   ittraining/mongodb   "bash"                   8 hours ago      Up 8 hours                                              mongo 
 +04d910a3c93d   nginx                "/docker-entrypoint.…"   8 hours ago      Up 8 hours          0.0.0.0:81->80/tcp, :::81->80/tcp   quirky_moore
 </code> </code>
  
Ligne 1151: Ligne 1131:
  
 <code> <code>
-root@debian9:~/myDocker# docker rm -fv myDocker+root@debian11:~/myDocker# docker rm -fv myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker run -d --name myDocker i2tch/mydocker "Up and Running" + 
-0cf8c8c1bdf4cb05d9852900ecdf171ad9abad0fce29a9f040d5d8436285db65 +root@debian11:~/myDocker# docker run -d --name myDocker i2tch/mydocker "Up and Running" 
-root@debian9:~/myDocker# docker logs myDocker +fd5ac836f674fe0bf7b5056e851cd15e4762a5e41b05e00d384bede5234e1f5f 
-Up and Running (18:13:33+ 
-Up and Running (18:13:36+root@debian11:~/myDocker# docker logs myDocker 
-Up and Running (18:13:39+Up and Running (17:14:23) 
-Up and Running (18:13:42+Up and Running (17:14:26) 
-root@debian9:~/myDocker# +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:~/myDocker#
 </code> </code>
  
Ligne 1166: Ligne 1150:
  
 <code> <code>
-root@debian9:~/myDocker# docker rm -fv myDocker+root@debian11:~/myDocker# docker rm -fv myDocker
 myDocker myDocker
-root@debian9:~/myDocker# docker run -d --name myDocker --env myVariable=1 i2tch/mydocker + 
-fbbe3b48c63310e37a3bad5fc962361c39c045a107f47980614efd6b2e8d3981 +root@debian11:~/myDocker# docker run -d --name myDocker --env myVariable=1 i2tch/mydocker 
-root@debian9:~/myDocker# docker logs myDocker +a9e02a8bb39df9d5c84fc1d58643bc38c228b0562731792e2356a801b50a9a14 
-mycommand (18:14:47) + 
-mycommand (18:14:48) +root@debian11:~/myDocker# docker logs myDocker 
-mycommand (18:14:49) +mycommand (17:15:35
-mycommand (18:14:50) +mycommand (17:15:36
-mycommand (18:14:51+mycommand (17:15:37
-mycommand (18:14:52+mycommand (17:15:38
-mycommand (18:14:53+mycommand (17:15:39
-mycommand (18:14:54+mycommand (17:15:40
-mycommand (18:14:55+mycommand (17:15:41
-mycommand (18:14:56+root@debian11:~/myDocker# 
-mycommand (18:14:57+
-root@debian9:~/myDocker# +
 </code> </code>
  
Ligne 1192: Ligne 1174:
  
 <code> <code>
-root@debian9:~/myDocker# cd .. +root@debian11:~/myDocker# cd .. 
-root@debian9:~# mkdir bestp + 
-root@debian9:~# cd bestp +root@debian11:~# mkdir bestp 
-root@debian9:~/bestp# vi Dockerfile + 
-root@debian9:~/bestp# cat Dockerfile+root@debian11:~# cd bestp 
 + 
 +root@debian11:~/bestp# vi Dockerfile 
 + 
 +root@debian11:~/bestp# cat Dockerfile
 FROM ubuntu:latest FROM ubuntu:latest
 RUN date +%N > /tmp/moment RUN date +%N > /tmp/moment
Ligne 1205: Ligne 1191:
 Le fichier Dokerfile contient une opération non idempotente. Le fichier Dokerfile contient une opération non idempotente.
  
-<WRAP center round important>+<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. **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.
 </WRAP> </WRAP>
Ligne 1212: Ligne 1198:
  
 <code> <code>
-root@debian9:~/bestp# docker build -t testcache . +root@debian11:~/bestp# docker build -t testcache . 
-Sending build context to Docker daemon  2.048kB +[+] Building 0.9s (6/6) FINISHED                                                                                                                                    docker:default 
-Step 1/: FROM ubuntu:latest + => [internal] load build definition from Dockerfile                                                                                                                          0.2s 
- ---94e814e2efa8 + => => transferring dockerfile: 123B                                                                                                                                          0.0s 
-Step 2/4 : RUN date +%N > /tmp/moment + => [internal] load .dockerignore                                                                                                                                             0.1s 
- ---Running in 6c8c677c1549 + => => transferring context: 2B                                                                                                                                               0.0s 
-Removing intermediate container 6c8c677c1549 + => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                              0.0s 
- ---66c3c88c57bb + => [1/2] FROM docker.io/library/ubuntu:latest                                                                                                                                0.1s 
-Step 3/4 : ENTRYPOINT ["more"+ =[2/2] RUN date +%N > /tmp/moment                                                                                                                                          0.4s 
- ---Running in e9658e591172 + =exporting to image                                                                                                                                                        0.1s 
-Removing intermediate container e9658e591172 + ==exporting layers                                                                                                                                                       0.1s 
- ---81cb68241ec9 + ==> writing image sha256:842ab4a40890a1b5fe7a3af5a41513c6edd5fd2da503b82c375f350671b62707                                                                                  0.0s 
-Step 4/4 CMD ["/tmp/moment"] + ==naming to docker.io/library/testcache                                                                                                                                  0.0s
- ---Running in 48974dc12faa +
-Removing intermediate container 48974dc12faa +
- ---c55a42a18572 +
-Successfully built c55a42a18572 +
-Successfully tagged testcache:latest +
-root@debian9:~/bestp#+
 </code> </code>
  
Ligne 1236: Ligne 1216:
  
 <code> <code>
-root@debian9:~/bestp# docker run --name test1 -it testcache +root@debian11:~/bestp# docker run --name test1 -it testcache 
-369009216+771723987
 </code> </code>
  
Ligne 1243: Ligne 1223:
  
 <code> <code>
-root@debian9:~/bestp# docker rm test1+root@debian11:~/bestp# docker rm test1
 test1 test1
-root@debian9:~/bestp# docker build -t testcache . + 
-Sending build context to Docker daemon  2.048kB +root@debian11:~/bestp# docker build -t testcache . 
-Step 1/: FROM ubuntu:latest +[+] Building 0.3s (6/6) FINISHED                                                                                                                                    docker:default 
- ---94e814e2efa8 + => [internal] load .dockerignore                                                                                                                                             0.1s 
-Step 2/4 : RUN date +%N > /tmp/moment + => => transferring context: 2B                                                                                                                                               0.0s 
- ---Using cache + => [internal] load build definition from Dockerfile                                                                                                                          0.1s 
- ---66c3c88c57bb + => => transferring dockerfile: 123B                                                                                                                                          0.0s 
-Step 3/4 : ENTRYPOINT ["more"+ => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                              0.0s 
- ---Using cache + => [1/2] FROM docker.io/library/ubuntu:latest                                                                                                                                0.0s 
- ---81cb68241ec9 + =CACHED [2/2] RUN date +%N > /tmp/moment                                                                                                                                   0.0s 
-Step 4/4 CMD ["/tmp/moment"] + =exporting to image                                                                                                                                                        0.0s 
- ---Using cache + ==exporting layers                                                                                                                                                       0.0s 
- ---c55a42a18572 + ==> writing image sha256:842ab4a40890a1b5fe7a3af5a41513c6edd5fd2da503b82c375f350671b62707                                                                                  0.0s 
-Successfully built c55a42a18572 + ==naming to docker.io/library/testcache                                                                                                                                  0.0s 
-Successfully tagged testcache:latest +
-root@debian9:~/bestp# +
 </code> </code>
  
Ligne 1266: Ligne 1244:
  
 <code> <code>
-root@debian9:~/bestp# docker run --name test1 -it testcache +root@debian11:~/bestp# docker run --name test1 -it testcache 
-369009216+771723987
 </code> </code>
  
-<WRAP center round important>+<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'exécution du deuxième conteneur. La raison que ceci n'est pas le cas est l'utilisation dans la deuxième compilation du cache. Si cette commande avait été quelque chose de plus importante telle apt-get upgrade, le résultat pourrait être génant ! **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'exécution du deuxième conteneur. La raison que ceci n'est pas le cas est l'utilisation dans la deuxième compilation du cache. Si cette commande avait été quelque chose de plus importante telle apt-get upgrade, le résultat pourrait être génant !
 </WRAP> </WRAP>
Ligne 1277: Ligne 1255:
  
 <code> <code>
-root@debian9:~/bestp# vi Dockerfile  +root@debian11:~/bestp# vi Dockerfile 
-root@debian9:~/bestp# cat Dockerfile + 
 +root@debian11:~/bestp# cat Dockerfile
 FROM ubuntu:latest FROM ubuntu:latest
 RUN date +%N > /tmp/moment \ RUN date +%N > /tmp/moment \
Ligne 1289: Ligne 1268:
  
 <code> <code>
-root@debian9:~/bestp# docker rm test1+root@debian11:~/bestp# docker rm test1
 test1 test1
-root@debian9:~/bestp# docker build -t testcache . + 
-Sending build context to Docker daemon  2.048kB +root@debian11:~/bestp# docker build -t testcache . 
-Step 1/: FROM ubuntu:latest +[+] Building 0.7s (6/6) FINISHED                                                                                                                                    docker:default 
- ---94e814e2efa8 + => [internal] load .dockerignore                                                                                                                                             0.1s 
-Step 2/4 : RUN date +%N > /tmp/moment     && echo "V1.1" > /tmp/version + => => transferring context: 2B                                                                                                                                               0.0s 
- ---Running in 3d2a5cee6ac8 + => [internal] load build definition from Dockerfile                                                                                                                          0.1s 
-Removing intermediate container 3d2a5cee6ac8 + => => transferring dockerfile: 159B                                                                                                                                          0.0s 
- ---75d0498a9676 + => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                              0.0s 
-Step 3/4 : ENTRYPOINT ["more"+ => CACHED [1/2] FROM docker.io/library/ubuntu:latest                                                                                                                         0.0s 
- ---Running in 88c0cec68659 + =[2/2] RUN date +%N > /tmp/moment     && echo "V1.1" > /tmp/version                                                                                                        0.4s 
-Removing intermediate container 88c0cec68659 + =exporting to image                                                                                                                                                        0.1s 
- ---2aee524c8da4 + ==exporting layers                                                                                                                                                       0.1s 
-Step 4/4 CMD ["/tmp/moment"] + ==> writing image sha256:5a36b1c7ec76e7bde962c41f5f5dcc11ae0ce3968e4953fbababcc8b7b282dab                                                                                  0.0s 
- ---Running in 82d2162bb701 + ==naming to docker.io/library/testcache                                                                                                                                  0.0s
-Removing intermediate container 82d2162bb701 +
- ---a54c4af89994 +
-Successfully built a54c4af89994 +
-Successfully tagged testcache:latest+
 </code> </code>
  
Ligne 1314: Ligne 1289:
  
 <code> <code>
-root@debian9:~/bestp# docker run --name test1 -it testcache +root@debian11:~/bestp# docker run --name test1 -it testcache 
-746997174+063819144
 </code> </code>
  
 +=====LAB #3 - Installer un Registre Privé=====
 +
 +====3.1 - Installer un Registre Local====
 +
 +Pour installer un registre privé, il convient d'utiliser une image publique de docker :
 +
 +<code>
 +root@debian11:~/bestp# cd ..
 +
 +root@debian11:~# docker run -d --name registry -p 88:5000 registry:latest
 +Unable to find image 'registry:latest' locally
 +latest: Pulling from library/registry
 +c926b61bad3b: Pull complete 
 +5501dced60f8: Pull complete 
 +e875fe5e6b9c: Pull complete 
 +21f4bf2f86f9: Pull complete 
 +98513cca25bb: Pull complete 
 +Digest: sha256:0a182cb82c93939407967d6d71d6caf11dcef0e5689c6afe2d60518e3b34ab86
 +Status: Downloaded newer image for registry:latest
 +272df4a849bcbc58a70d6c8e1e74751f24e485fd8ad6817427ef180b9f28b5f8
 +</code>
 +
 +Utilisez maintenant **lynx** à partir d'un terminal de votre machine **hôte Docker** pour vérifier que le registre est actif :
 +
 +<code>
 +root@debian11:~# lynx --dump http://localhost:88/v2
 +{}root@debian11:~# 
 +</code>
 +
 +<WRAP center round important 50%>
 +**Important** - Notez la réponse du serveur est **{}** soit une liste JSON vide.
 +</WRAP>
 +
 +Renommez l'image **i2tch/mydocker** afin de pointer vers le nouveau registre :
 +
 +<code>
 +root@debian11:~# docker tag i2tch/mydocker localhost:88/mydocker
 +</code>
 +
 +Envoyez votre image **localhost:88/mydocker** sur ce nouveau registre :
 +
 +<code>
 +root@debian11:~# docker push localhost:88/mydocker
 +Using default tag: latest
 +The push refers to repository [localhost:88/mydocker]
 +f981bd64e799: Pushed 
 +74ddd0ec08fa: Pushed 
 +latest: digest: sha256:32f7a11d8a8523bb5b4ac0986844d569ca96df4d1875e7e678a885ee3a3c61c3 size: 736
 +</code>
 +
 +Constatez maintenant la présence de l'image dans le registre :
 +
 +<code>
 +root@debian11:~# lynx --dump http://localhost:88/v2/mydocker/tags/list
 +{"name":"mydocker","tags":["latest"]}
 +</code>
 +
 +====3.2 - Créer un Serveur de Registre Dédié====
 +
 +Actuellement, le registre privé créé ci-dessus n'est pas accessible à partir du réseau local car il est référencé par localhost. Il convient donc maintenant de mettre en place un serveur dédié.
 +
 +Connectez-vous à la VM **CentOS_10.0.2.45_SSH** à partir de votre VM **Debian_10.0.2.46_SSH** :
 +
 +<code>
 +root@debian11:~# ssh -l trainee 10.0.2.45
 +trainee@10.0.2.45's password: trainee
 +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 ~]$
 +</code>
 +
 +Devenez root :
 +
 +<code>
 +[trainee@centos8 ~]$ su -
 +Password: fenestros
 +[root@centos8 ~]# 
 +</code>
 +
 +Modifiez le nom d'hôte de la machine :
 +
 +<code>
 +[root@centos8 ~]# nmcli general hostname myregistry.i2tch.loc
 +[root@centos8 ~]# hostname
 +myregistry.i2tch.loc
 +</code>
 +
 +Editez le fichier **/etc/hosts** et changez l'entrée pour l'adresse IP 10.0.2.61 :
 +
 +<code>
 +[root@centos8 ~]# vi /etc/hosts
 +[root@centos8 ~]# cat /etc/hosts
 +127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
 +::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 +10.0.2.45       myregistry.i2tch.loc
 +10.0.2.46       debian11.i2tch.loc
 +</code>
 +
 +Créez maintenant un certificat auto-signé avec **openssl** :
 +
 +<code>
 +[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:i2tch.loc,DNS:myregistry.i2tch.loc
 +
 +[ 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/domain.key -x509 -days 365 -out certs/domain.crt
 +Generating a RSA private key
 +...............................................................................................................................................................................................++++
 +......++++
 +writing new private key to 'certs/domain.key'
 ----- -----
-<html+ 
-<div align="center"> +[root@centos8 /]# ls certs/ 
-Copyright © 2021 Hugh NORRIS +domain.crt  domain.key 
-</div+</code> 
-</html>+ 
 +Déconnectez-vous de la VM **CentOS8_10.0.2.45_SSH** : 
 + 
 +<code> 
 +[root@centos8 /]# exit 
 +logout 
 +[trainee@centos8 ~]$ exit 
 +logout 
 +Connection to 10.0.2.45 closed. 
 +root@debian11:~# 
 +</code> 
 + 
 +Re-connectez-vous à la VM **CentOS8_10.0.2.45_SSH** : 
 + 
 +<code> 
 +root@debian11:~# ssh -l trainee 10.0.2.45 
 +trainee@10.0.2.45's password: trainee 
 +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 ~]$ 
 +</code> 
 + 
 +Devenez root : 
 + 
 +<code> 
 +[trainee@myregistry ~]$ su - 
 +Password: fenestros 
 +[root@myregistry ~]#  
 +</code> 
 + 
 +Créez un conteneur en mode sécurisé avec TLS à partir de l'image registry : 
 + 
 +<code> 
 +[root@myregistry ~]# docker run -d -p 5000:5000 --name registry -v /certs:/certs -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key registry:latest 
 +Unable to find image 'registry:latest' locally 
 +latest: Pulling from library/registry 
 +c926b61bad3b: Pull complete  
 +5501dced60f8: Pull complete  
 +e875fe5e6b9c: Pull complete  
 +21f4bf2f86f9: Pull complete  
 +98513cca25bb: Pull complete  
 +Digest: sha256:0a182cb82c93939407967d6d71d6caf11dcef0e5689c6afe2d60518e3b34ab86 
 +Status: Downloaded newer image for registry:latest 
 +bf0d4fe9fcb121f9c2d9e85b8f2bb54b01397602ef0dcefdfc71327acf832fec 
 + 
 +[root@myregistry ~]# docker ps -a 
 +CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS                    PORTS                                       NAMES 
 +bf0d4fe9fcb1   registry:latest   "/entrypoint.sh /etc…  47 seconds ago   Up 44 seconds             0.0.0.0:5000->5000/tcp, :::5000->5000/tcp   registry 
 +90267aac9800   hello-world       "/hello"                 15 hours ago     Exited (0) 15 hours ago                                               eloquent_chatelet 
 +</code> 
 + 
 +Envoyez une copie du fichier **/certs/domain.crt** vers le répertoire /tmp de la machine virtuelle **Debian11_10.0.2.46** en le renommant **ca.crt** : 
 + 
 +<code> 
 +[root@myregistry ~]# scp /certs/domain.crt trainee@10.0.2.46:/tmp/ca.crt 
 +The authenticity of host '10.0.2.46 (10.0.2.46)' can't be established. 
 +ECDSA key fingerprint is SHA256:JFem/0UXFw0aDAOSfOS3vsOGsSDl1wPOza6ybTGO7/8. 
 +Are you sure you want to continue connecting (yes/no/[fingerprint])? yes 
 +Warning: Permanently added '10.0.2.46' (ECDSA) to the list of known hosts. 
 +trainee@10.0.2.46's password:  
 +domain.crt                                                                                                                                                                  100% 2053     2.9MB/  00:00    
 +</code> 
 + 
 +===Configurer le Client=== 
 + 
 +Sortez de la VM **CentOS8_10.0.2.45_SSH** : 
 + 
 +<code> 
 +[root@myregistry ~]# exit 
 +logout 
 +[trainee@myregistry ~]$ exit 
 +logout 
 +Connection to 10.0.2.45 closed. 
 +root@debian11:~# 
 +</code> 
 + 
 +Supprimez le conteneur **registry** : 
 + 
 +<code> 
 +root@debian11:~# docker rm -f registry 
 +registry 
 +</code> 
 + 
 +ainsi que l'image du registry : 
 + 
 +<code> 
 +root@debian11:~# docker rmi registry:latest 
 +Untagged: registry:latest 
 +Untagged: registry@sha256:0a182cb82c93939407967d6d71d6caf11dcef0e5689c6afe2d60518e3b34ab86 
 +Deleted: sha256:909c3ff012b7f9fc4b802b73f250ad45e4ffa385299b71fdd6813f70a6711792 
 +Deleted: sha256:577c3b283118ca6108a6a8c8a0a00eff666dec82c482dd239dfed49f31553df6 
 +Deleted: sha256:2ba6acf6ed95c86cfb2c830693135513bc019a0c0cf8f2c58990bc215995699f 
 +Deleted: sha256:65920463e77382a5cbe8da3e814c4449fc665487c8a9fa4ac27179e809f5ba2e 
 +Deleted: sha256:54501ccbeaec2665849d200fc4a61ab7254ff0f3bd31ab673879fe321fa2ad7f 
 +Deleted: sha256:9fe9a137fd002363ac64f5af66146702432b638a83ee0c5b620c40a9e433e813 
 +</code> 
 + 
 +Renommez l'image **i2tch/mydocker** afin de pointer vers le serveur de registre : 
 + 
 +<code> 
 +root@debian11:~# docker tag i2tch/mydocker myregistry.i2tch.loc:5000/mydocker 
 + 
 +root@debian11:~# docker images 
 +REPOSITORY                           TAG       IMAGE ID       CREATED        SIZE 
 +testcache                            latest    5a36b1c7ec76   4 days ago     77.8MB 
 +<none>                               <none>    842ab4a40890   4 days ago     77.8MB 
 +i2tch/mydocker                       latest    c5a41438d278   4 days ago     231MB 
 +localhost:88/mydocker                latest    c5a41438d278   4 days ago     231MB 
 +myregistry.i2tch.loc:5000/mydocker   latest    c5a41438d278   4 days ago     231MB 
 +i2tch/mongodb2                       latest    56e5b1fb4284   4 days ago     352MB 
 +i2tch/mongodb1                       latest    72fad0b7e0c2   4 days ago     352MB 
 +ittraining/mongodb                   latest    fb3c6d5d186a   5 days ago     1.11GB 
 +ubuntu                               latest    b6548eacb063   2 weeks ago    77.8MB 
 +nginx                                latest    a6bd71f48f68   3 weeks ago    187MB 
 +hello-world                          latest    9c7a54a9a43c   7 months ago   13.3kB 
 +centos                               latest    5d0da3dc9764   2 years ago    231MB 
 +</code> 
 + 
 +Editez le fichier **/etc/hosts** afin de pointer le 10.0.2.45 vers le nom **myregistry.i2tch.loc** : 
 + 
 +<code> 
 +root@debian11:~# vi /etc/hosts 
 + 
 +root@debian11:~# cat /etc/hosts 
 +127.0.0.1       localhost 
 +10.0.2.46       debian11.i2tch.loc      debian11 
 +10.0.2.45       myregistry.i2tch.loc    myregistry 
 + 
 +# The following lines are desirable for IPv6 capable hosts 
 +::1     localhost ip6-localhost ip6-loopback 
 +ff02::1 ip6-allnodes 
 +ff02::2 ip6-allrouters 
 +</code> 
 + 
 +Déplacez le fichier **/tmp/ca.crt** vers le répertoire **/etc/docker/certs.d/myregistry:5000/** : 
 + 
 +<code> 
 +root@debian11:~# mkdir -p /etc/docker/certs.d/myregistry:5000 
 + 
 +root@debian11:~# mv /tmp/ca.crt /etc/docker/certs.d/myregistry:5000/ 
 +</code> 
 + 
 +Créez le fichier **/etc/docker/daemon.json** pour accepter le certificat auto-signé : 
 + 
 +<code> 
 +root@debian11:~# vi /etc/docker/daemon.json 
 + 
 +root@debian11:~# cat /etc/docker/daemon.json 
 +{"insecure-registries" : ["myregistry.i2tch.loc:5000"]} 
 +</code> 
 + 
 +Re-démarrez le service docker : 
 + 
 +<code> 
 +root@debian11:~# systemctl restart docker 
 +</code> 
 + 
 +Testez la réponse du registre : 
 + 
 +<code> 
 +root@debian11:~# curl -k https://myregistry:5000/v2/ 
 +{}root@debian11:~# 
 +</code> 
 + 
 +Finalement, envoyez l'image au registre : 
 + 
 +<code> 
 +root@debian11:~# docker push myregistry.i2tch.loc:5000/mydocker 
 +Using default tag: latest 
 +The push refers to repository [myregistry.i2tch.loc:5000/mydocker] 
 +f981bd64e799: Pushed  
 +74ddd0ec08fa: Pushed  
 +latest: digest: sha256:32f7a11d8a8523bb5b4ac0986844d569ca96df4d1875e7e678a885ee3a3c61c3 size: 736 
 +</code> 
 + 
 +----- 
 + 
 +Copyright © 2024 Hugh Norris.
Menu