Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
elearning:workbooks:docker1:drf02 [2020/08/10 13:49] – admin | elearning:workbooks:docker1:drf02 [2021/12/29 10:32] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version : **2020.01** | + | Version : **2022.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======DOF103 - Gestion des Volumes, du Réseau et des Ressources====== | + | ======DOF103 - Gérer les Images Docker====== |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **DOF103 - Gestion des Volumes, du Réseau et des Ressources** | + | * **DOF103 - Gérer les Images Docker** |
- | * LAB #6 - Gestion des Volumes | + | * Contenu du Module |
- | * Gestion Automatique par Docker | + | * LAB #1 - Re-créer une image officielle docker |
- | * Gestion Manuelle | + | * 1.1 - Utilisation |
- | * LAB #7 - Gestion du Réseau | + | * 1.2 - FROM |
- | * L' | + | * 1.3 - RUN |
- | * Bridge | + | * 1.4 - ENV |
- | * None | + | * 1.5 - VOLUME |
- | * Liens | + | * 1.6 - COPY |
- | * Lancer Wordpress dans un container | + | * 1.7 - ENTRYPOINT |
- | * Gestion d'une Architecture de Microservices | + | * 1.8 - EXPOSE |
- | * LAB #8 - Superviser les Conteneurs | + | * 1.9 - CMD |
- | * Les Journaux | + | * 1.10 - Autres Commandes |
- | * Les Processus | + | * LAB #2 - Créer un Dockerfile |
- | * L' | + | * 2.1 - Création et test du script |
- | * LAB #9 - Gestion des Ressources | + | * 2.2 - Bonnes Pratiques liées au Cache |
- | * Limiter la Mémoire | + | |
- | =====LAB #5 - Gestion des Volumes===== | + | =====LAB #1 - Re-créer une image officielle docker===== |
- | Lancez | + | ====1.1 - Utilisation d'un Dockerfile==== |
+ | |||
+ | Bien que la compilation des images soient assuré par Docker Hub, il est tout à fait possible | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a | + | root@debian9: |
+ | root@debian9: | ||
</ | </ | ||
- | ====Gestion Automatique de Volumes par Docker==== | + | Le Docker |
- | Vérifiez que le processus est bien démarré dans le conteneur | + | <file txt Dockerfile> |
+ | FROM ubuntu:bionic | ||
- | < | + | # add our user and group first to make sure their IDs get assigned consistently, |
- | root@debian9: | + | RUN groupadd |
- | CONTAINER ID IMAGE | + | |
- | b9773e4aa06d | + | |
- | </ | + | |
- | Identifiez ensuite le point de montage du répertoire **/data/db** du conteneur : | + | RUN set -eux; \ |
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | ca-certificates \ | ||
+ | jq \ | ||
+ | numactl \ | ||
+ | ; \ | ||
+ | if ! command -v ps > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends procps; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
- | < | + | # grab gosu for easy step-down from root (https://github.com/tianon/gosu/releases) |
- | root@debian9:~# docker inspect mongo2 | + | ENV GOSU_VERSION 1.11 |
- | ... | + | # grab "js-yaml" |
- | " | + | ENV JSYAML_VERSION 3.13.0 |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Driver": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ... | + | |
- | " | + | |
- | "/data/configdb": | + | |
- | "/data/ | + | |
- | }, | + | |
- | ... | + | |
- | </ | + | |
- | En regardant le contenu du répertoire **/data/db**, on constate une arborescence classique de stockage de données de mongodb | + | RUN set -ex; \ |
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; | ||
+ | # gpg --batch --verify / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | chmod +x / | ||
+ | gosu --version; \ | ||
+ | gosu nobody true; \ | ||
+ | \ | ||
+ | wget -O /js-yaml.js " | ||
+ | # TODO some sort of download verification here | ||
+ | \ | ||
+ | apt-get purge -y --auto-remove wget | ||
- | < | + | RUN mkdir /docker-entrypoint-initdb.d |
- | root@debian9: | + | |
- | journal | + | |
- | </ | + | |
- | Arrêtez et supprimez le conteneur **mongo2** | + | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B |
+ | RUN set -ex; \ | ||
+ | export GNUPGHOME=" | ||
+ | for key in $GPG_KEYS; do \ | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys " | ||
+ | done; \ | ||
+ | gpg --batch --export $GPG_KEYS > / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | apt-key list | ||
- | < | + | # Allow build-time overrides |
- | root@debian9: | + | # Options for MONGO_PACKAGE: |
- | mongo2 | + | # Options for MONGO_REPO: repo.mongodb.org OR repo.mongodb.com |
- | root@debian9: | + | # Example: |
- | CONTAINER ID IMAGE | + | ARG MONGO_PACKAGE=mongodb-org-unstable |
- | ea239635e141 | + | ARG MONGO_REPO=repo.mongodb.org |
- | 21b0490a93dd | + | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} |
- | b9773e4aa06d | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9:~# docker ps -a | + | |
- | CONTAINER ID IMAGE | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | </ | + | |
- | Re-créez maintenant un conteneur à partir de l' | + | ENV MONGO_MAJOR 4.1 |
+ | ENV MONGO_VERSION 4.1.9 | ||
+ | # bashbrew-architectures:amd64 arm64v8 s390x | ||
+ | RUN echo "deb http:// | ||
- | < | + | RUN set -x \ |
- | root@debian9: | + | && apt-get update \ |
- | a8382642c4e849337e12a60419b10f63ea21251dfcc2c6050284ca3eed7fa13d | + | && apt-get install |
- | root@debian9: | + | ${MONGO_PACKAGE}=$MONGO_VERSION \ |
- | CONTAINER ID IMAGE | + | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ |
- | a8382642c4e8 | + | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ |
- | ea239635e141 | + | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ |
- | 21b0490a93dd | + | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ |
- | bdb4bc0f81de | + | && rm -rf /var/lib/apt/lists/* \ |
- | f5b45072b831 | + | && rm -rf /var/lib/ |
- | 9731a48f126a | + | && mv /etc/mongod.conf /etc/mongod.conf.orig |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | </ | + | |
- | Utilisez de nouveau la commande **docker inspect** pour identifier le point de montage du répertoire **/data/db** : | + | RUN mkdir -p / |
+ | && chown -R mongodb:mongodb /data/db / | ||
+ | VOLUME /data/db / | ||
- | < | + | COPY docker-entrypoint.sh /usr/local/bin/ |
- | root@debian9: | + | ENTRYPOINT [" |
- | ... | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Destination": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ... | + | |
- | </ | + | |
- | <WRAP center round important> | + | EXPOSE 27017 |
- | **Important** : Notez que le répertoire des données du précédent conteneur, **/ | + | CMD [" |
- | </WRAP> | + | </file> |
- | Les conteneurs n' | + | Le fichier docker-entrypoint.sh sert à lancer le serveur mongodb |
- | <code> | + | <file txt docker-entrypoint.sh> |
- | root@debian9: | + | #!/bin/bash |
- | total 52 | + | set -Eeuo pipefail |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 3bf724ceb38ce0792469d7e403f05b6794f27e0aa72bda51a8ab75b2df5ae87c | + | |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 46d11d005d05757609ff76159ce0992d210089c5247fa54b024706a20b0de501 | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 76dcc0ccbe6604278cf8e8da0398a807f5d0719087f17c227c8504be24456d43 | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 9c84c2d1a0db811a3c13dce354ba21169f3073513c8d025dd96c5f902364d44a | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 a6177cf4b46089356280f084dd2e272f673aa4a81accb53f031267fafcee6050 | + | |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 cc38fa97138adc55976aa16993d8920c5f7da922ad1b2a07936d30cc82d59f38 | + | |
- | -rw------- 1 root root 32768 Sep 7 09:43 metadata.db | + | |
- | </ | + | |
- | <WRAP center round important> | + | if [ "${1:0:1}" = '-' |
- | **Important** | + | set -- mongod " |
- | </ | + | fi |
- | ====Gestion Manuelle d'un Volume==== | + | originalArgOne=" |
- | Arrêtez et supprimez le conteneur **mongo2** puis re-créez un conteneur avec un volume spécifique pour contenir les données placées dans **/data/db** du conteneur par mongodb | + | # allow the container to be started with `--user` |
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
- | < | + | # make sure we can write to stdout and stderr as "mongodb" |
- | root@debian9: | + | # (for our "initdb" |
- | mongo2 | + | chown --dereference mongodb |
- | root@debian9: | + | # ignore errors thanks to https://github.com/docker-library/mongo/issues/149 |
- | mongo2 | + | |
- | root@debian9: | + | |
- | 3cf093d72b9e3739f2cb288e571244e494b7518292c31994ee012e3620bb0e98 | + | |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | 3cf093d72b9e | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08:53: | + | |
- | 2017-09-07T08:53: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | 2017-09-07T08: | + | |
- | </ | + | |
- | Notez que cette fois-ci, docker a créé un répertoire **persistent_data** dans le répertoire **/ | + | exec gosu mongodb " |
+ | fi | ||
- | < | + | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. |
- | root@debian9:~# ls -l /var/lib/docker/volumes/ | + | # https://docs.mongodb.com/manual/administration/production-notes/# |
- | total 68 | + | if [[ " |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 3bf724ceb38ce0792469d7e403f05b6794f27e0aa72bda51a8ab75b2df5ae87c | + | numa=' |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 46d11d005d05757609ff76159ce0992d210089c5247fa54b024706a20b0de501 | + | if $numa true &> /dev/null; then |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:46 511e23f818d5cf60f4333a3fe8fd2e4333c900dec6eee97f70448bfb0091184d | + | set -- $numa " |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:53 5ca72be4140ecf1271efe7342cf7cd58ce66fc3673d12c04b8503603b8cee66c | + | fi |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 76dcc0ccbe6604278cf8e8da0398a807f5d0719087f17c227c8504be24456d43 | + | fi |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 9c84c2d1a0db811a3c13dce354ba21169f3073513c8d025dd96c5f902364d44a | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 a6177cf4b46089356280f084dd2e272f673aa4a81accb53f031267fafcee6050 | + | |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 cc38fa97138adc55976aa16993d8920c5f7da922ad1b2a07936d30cc82d59f38 | + | |
- | -rw------- 1 root root 65536 Sep 7 09:53 metadata.db | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:46 persistent_data | + | |
- | </ | + | |
- | Arrêtez et supprimez le conteneur **mongo2** puis re-créez un conteneur en utilisant le même volume spécifique pour contenir les données placées dans **/ | + | # usage: file_env VAR [DEFAULT] |
+ | # ie: file_env ' | ||
+ | # (will allow for " | ||
+ | # " | ||
+ | file_env() { | ||
+ | local var=" | ||
+ | local fileVar=" | ||
+ | local def=" | ||
+ | if [ " | ||
+ | echo >&2 " | ||
+ | exit 1 | ||
+ | fi | ||
+ | local val=" | ||
+ | if [ " | ||
+ | val=" | ||
+ | elif [ " | ||
+ | val=" | ||
+ | fi | ||
+ | export " | ||
+ | unset " | ||
+ | } | ||
- | < | + | # see https:// |
- | root@debian9: | + | _mongod_hack_have_arg() { |
- | mongo2 | + | local checkArg=" |
- | root@debian9: | + | local arg |
- | mongo2 | + | for arg; do |
- | root@debian9: | + | case " |
- | ad672c3038245c25a36162d05820c21f7250557ac342582d0908d3ca33799e37 | + | " |
- | root@debian9: | + | return 0 |
- | CONTAINER ID IMAGE | + | ;; |
- | ad672c303824 | + | esac |
- | ea239635e141 | + | done |
- | 21b0490a93dd | + | return 1 |
- | bdb4bc0f81de | + | } |
- | f5b45072b831 | + | # _mongod_hack_get_arg_val '--some-arg' " |
- | 9731a48f126a | + | _mongod_hack_get_arg_val() { |
- | eacd70596e23 | + | local checkArg=" |
- | cffb4456e9c4 | + | while [ " |
- | </ | + | local arg=" |
+ | case " | ||
+ | " | ||
+ | echo " | ||
+ | return 0 | ||
+ | ;; | ||
+ | " | ||
+ | echo "${arg#$checkArg=}" | ||
+ | return 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | return 1 | ||
+ | } | ||
+ | declare | ||
+ | # _mongod_hack_ensure_arg ' | ||
+ | # set -- "${mongodHackedArgs[@]}" | ||
+ | _mongod_hack_ensure_arg() { | ||
+ | local ensureArg="$1"; shift | ||
+ | mongodHackedArgs=( " | ||
+ | if ! _mongod_hack_have_arg | ||
+ | mongodHackedArgs+=( " | ||
+ | fi | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- "${mongodHackedArgs[@]}" | ||
+ | _mongod_hack_ensure_no_arg() { | ||
+ | local ensureNoArg="$1"; shift | ||
+ | mongodHackedArgs=() | ||
+ | while [ "$#" -gt 0 ]; do | ||
+ | local arg=" | ||
+ | if [ " | ||
+ | continue | ||
+ | fi | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_no_arg_val() { | ||
+ | local ensureNoArg=" | ||
+ | mongodHackedArgs=() | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | case " | ||
+ | " | ||
+ | shift # also skip the value | ||
+ | continue | ||
+ | ;; | ||
+ | "$ensureNoArg" | ||
+ | # value is already included | ||
+ | continue | ||
+ | ;; | ||
+ | esac | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_arg_val ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_arg_val() { | ||
+ | local ensureArg="$1"; shift | ||
+ | local ensureVal=" | ||
+ | _mongod_hack_ensure_no_arg_val " | ||
+ | mongodHackedArgs+=( " | ||
+ | } | ||
- | Encore une fois, cherchez le point de montage de **/ | + | # _js_escape |
+ | _js_escape() { | ||
+ | jq --null-input --arg ' | ||
+ | } | ||
- | <code> | + | jsonConfigFile=" |
- | root@debian9:~# docker | + | tempConfigFile=" |
+ | _parse_config() { | ||
+ | if [ -s " | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | local configPath | ||
+ | if configPath=" | ||
+ | # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) | ||
+ | # see https:// | ||
+ | mongo --norc --nodb --quiet --eval " | ||
+ | jq ' | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | return 1 | ||
+ | } | ||
+ | dbPath= | ||
+ | _dbPath() { | ||
+ | if [ -n " | ||
+ | echo " | ||
+ | return | ||
+ | fi | ||
+ | |||
+ | if ! dbPath=" | ||
+ | if _parse_config " | ||
+ | dbPath=" | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | if _mongod_hack_have_arg --configsvr " | ||
+ | _parse_config " | ||
+ | && | ||
+ | && | ||
+ | }; then | ||
+ | # if running as config server, then the default dbpath is / | ||
+ | # https:// | ||
+ | dbPath=/ | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | : " | ||
+ | |||
+ | echo " | ||
+ | } | ||
+ | |||
+ | if [ " | ||
+ | file_env ' | ||
+ | file_env ' | ||
+ | # pre-check a few factors to see if it's even worth bothering with initdb | ||
+ | shouldPerformInitdb= | ||
+ | if [ " | ||
+ | # if we have a username/ | ||
+ | _mongod_hack_ensure_arg ' | ||
+ | set -- " | ||
+ | shouldPerformInitdb=' | ||
+ | elif [ " | ||
+ | cat >& | ||
+ | error: missing ' | ||
+ | both must be specified for a user to be created | ||
+ | EOF | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | # if we've got any / | ||
+ | for f in / | ||
+ | case " | ||
+ | *.sh|*.js) # this should match the set of files we check for below | ||
+ | shouldPerformInitdb=" | ||
+ | break | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | # check for a few known paths (to determine whether we've already initialized and should thus skip our initdb scripts) | ||
+ | if [ -n " | ||
+ | dbPath=" | ||
+ | for path in \ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ; do | ||
+ | if [ -e " | ||
+ | shouldPerformInitdb= | ||
+ | break | ||
+ | fi | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | if [ -n " | ||
+ | mongodHackedArgs=( " | ||
+ | if _parse_config " | ||
+ | _mongod_hack_ensure_arg_val --config " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 " | ||
+ | _mongod_hack_ensure_arg_val --port 27017 " | ||
+ | _mongod_hack_ensure_no_arg --bind_ip_all " | ||
+ | |||
+ | # remove " | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_no_arg --auth " | ||
+ | if [ " | ||
+ | _mongod_hack_ensure_no_arg_val --replSet " | ||
+ | fi | ||
+ | |||
+ | sslMode=" | ||
+ | _mongod_hack_ensure_arg_val --sslMode " | ||
+ | |||
+ | if stat "/ | ||
+ | # https:// | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_arg_val --logpath "/ | ||
+ | else | ||
+ | initdbLogPath=" | ||
+ | echo >&2 " | ||
+ | _mongod_hack_ensure_arg_val --logpath " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg --logappend " | ||
+ | |||
+ | pidfile=" | ||
+ | rm -f " | ||
+ | _mongod_hack_ensure_arg_val --pidfilepath " | ||
+ | |||
+ | " | ||
+ | |||
+ | mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) | ||
+ | |||
+ | # check to see that our " | ||
+ | # https:// | ||
+ | tries=30 | ||
+ | while true; do | ||
+ | if ! { [ -s " | ||
+ | # bail ASAP if " | ||
+ | echo >& | ||
+ | echo >&2 " | ||
+ | echo >& | ||
+ | exit 1 | ||
+ | fi | ||
+ | if " | ||
+ | # success! | ||
+ | break | ||
+ | fi | ||
+ | (( tries-- )) | ||
+ | if [ " | ||
+ | echo >& | ||
+ | echo >&2 " | ||
+ | echo >& | ||
+ | exit 1 | ||
+ | fi | ||
+ | sleep 1 | ||
+ | done | ||
+ | |||
+ | if [ " | ||
+ | rootAuthDatabase=' | ||
+ | |||
+ | " | ||
+ | db.createUser({ | ||
+ | user: $(_js_escape " | ||
+ | pwd: $(_js_escape " | ||
+ | roles: [ { role: ' | ||
+ | }) | ||
+ | EOJS | ||
+ | fi | ||
+ | |||
+ | export MONGO_INITDB_DATABASE=" | ||
+ | |||
+ | echo | ||
+ | for f in /docker-entrypoint-initdb.d/ | ||
+ | case " | ||
+ | *.sh) echo "$0: running $f"; . " | ||
+ | *.js) echo "$0: running $f"; " | ||
+ | *) | ||
+ | esac | ||
+ | echo | ||
+ | done | ||
+ | |||
+ | " | ||
+ | rm -f " | ||
+ | |||
+ | echo | ||
+ | echo ' | ||
+ | echo | ||
+ | fi | ||
+ | |||
+ | # MongoDB 3.6+ defaults to localhost-only binding | ||
+ | if mongod --help 2>&1 | grep -q -- --bind_ip_all; | ||
+ | haveBindIp= | ||
+ | if _mongod_hack_have_arg --bind_ip " | ||
+ | haveBindIp=1 | ||
+ | elif _parse_config " | ||
+ | haveBindIp=1 | ||
+ | fi | ||
+ | if [ -z " | ||
+ | # so if no " | ||
+ | set -- " | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | unset " | ||
+ | fi | ||
+ | |||
+ | rm -f " | ||
+ | |||
+ | exec " | ||
+ | </ | ||
+ | |||
+ | Examinons chaque commande dans le Dockerfile : | ||
+ | |||
+ | ====1.2 - FROM==== | ||
+ | |||
+ | < | ||
+ | FROM ubuntu: | ||
+ | </ | ||
+ | |||
+ | Cette ligne définit l' | ||
+ | |||
+ | ====1.3 - RUN==== | ||
+ | |||
+ | < | ||
... | ... | ||
- | " | + | |
- | { | + | RUN groupadd -r mongodb && useradd -r -g mongodb mongodb |
- | " | + | |
- | " | + | RUN set -eux; \ |
- | " | + | apt-get update; \ |
- | " | + | apt-get install -y --no-install-recommends \ |
- | " | + | ca-certificates \ |
- | " | + | jq \ |
- | " | + | numactl \ |
- | " | + | ; \ |
- | }, | + | if ! command -v ps > /dev/null; then \ |
- | { | + | apt-get install -y --no-install-recommends procps; \ |
- | " | + | fi; \ |
- | " | + | rm -rf /var/lib/apt/lists/* |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
... | ... | ||
- | </code> | + | RUN set -ex; \ |
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; | ||
+ | gpg --batch --verify / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | chmod +x / | ||
+ | gosu --version; \ | ||
+ | gosu nobody true; \ | ||
+ | \ | ||
+ | wget -O /js-yaml.js " | ||
+ | # TODO some sort of download verification here | ||
+ | \ | ||
+ | apt-get purge -y --auto-remove wget | ||
+ | |||
+ | RUN mkdir / | ||
+ | ... | ||
+ | |||
+ | RUN set -ex; \ | ||
+ | export GNUPGHOME=" | ||
+ | for key in $GPG_KEYS; do \ | ||
+ | gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys " | ||
+ | done; \ | ||
+ | gpg --batch --export $GPG_KEYS > / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | apt-key list | ||
+ | ... | ||
+ | RUN set -x \ | ||
+ | && apt-get update \ | ||
+ | && apt-get install -y \ | ||
+ | ${MONGO_PACKAGE}=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ | ||
+ | && rm -rf / | ||
+ | && rm -rf / | ||
+ | && mv / | ||
+ | |||
+ | RUN mkdir -p /data/db / | ||
+ | && chown -R mongodb: | ||
+ | ... | ||
+ | </file> | ||
+ | |||
+ | Cette commande lance un processus dans la construction de l' | ||
+ | |||
+ | Il existe un autre syntaxe de la commande RUN appelé le format exec, à savoir : | ||
+ | |||
+ | RUN ["/ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** : Notez ici que l' | + | **Important** : La commande RUN est utilisée pour exécuter une commande passée en argument lors de la compilation |
</ | </ | ||
- | https:// | + | ====1.4 - ENV==== |
- | =====LAB #6 - Gestion | + | Cette commande permet de fixer la valeur d'une variable d' |
- | Docker fournit trois réseaux par défaut | + | < |
+ | ... | ||
+ | ENV GOSU_VERSION 1.11 | ||
+ | # grab " | ||
+ | ENV JSYAML_VERSION 3.13.0 | ||
+ | ... | ||
- | < | + | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B |
- | root@debian9: | + | ... |
- | NETWORK ID NAME DRIVER | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | 6bda460c97c6 | + | |
- | </ | + | |
- | ====Bridge==== | + | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} |
- | Ce type de réseau est limité aux conteneurs d'un hôte unique exécutant Docker. Les conteneurs ne peuvent communiquer qu' | + | ENV MONGO_MAJOR 4.1 |
+ | ENV MONGO_VERSION 4.1.95 | ||
+ | ... | ||
+ | </ | ||
- | Par défaut Docker fonctionne en mode **Pont** ou (// | + | **et** dans les conteneurs générés |
- | < | + | ====1.5 - VOLUME==== |
- | root@debian9: | + | |
- | 3: docker0: < | + | |
- | link/ether 02: | + | |
- | inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 | + | |
- | | + | |
- | </ | + | |
- | Démarrez un conteneur dénommé **resotest** à partir d'une image de CentOS : | + | < |
+ | ... | ||
+ | VOLUME /data/db / | ||
+ | ... | ||
+ | </ | ||
- | < | + | Cette commande expose les répertoires passés en argument afin qu'ils puissent être mappés vers des répertoires sur la machine hôte ou ailleurs, tel que nous avons vu avec l' |
- | root@debian9: | + | |
- | 2169360fcbfdbd6e68ea969a95edeb6fc42603c23ee42f03ceec286276519855 | + | |
- | </ | + | |
- | Lancez ensuite la commande **docker network inspect bridge** à partir de la machine virtuelle hôte de Debian_9 : | + | ====1.6 - COPY==== |
- | <code> | + | <file> |
- | root@debian9: | + | ... |
- | [ | + | COPY docker-entrypoint.sh / |
- | { | + | ... |
- | " | + | </file> |
- | " | + | |
- | " | + | Cette commande permet de récupérer les fichiers dans le contexte et de les copier dans l' |
- | " | + | |
- | " | + | **Attention** |
- | " | + | |
- | " | + | Il est possible d' |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | "com.docker.network.bridge.enable_icc": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | </ | + | |
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** : Notez ici que les conteneurs **mongo2** et **resotest** ne disposent pas de la même adresse que l'interface **docker0** | + | **Important** |
</ | </ | ||
- | Vous pouvez déconnecter un conteneur du réseau en utilisant la commande suivante : | + | ====1.7 - ENTRYPOINT==== |
- | <code> | + | <file> |
- | root@debian9: | + | ... |
- | root@debian9: | + | ENTRYPOINT ["docker-entrypoint.sh"] |
- | [ | + | ... |
- | { | + | </file> |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | "Gateway": | + | |
- | } | + | |
- | | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | </code> | + | |
- | Créez maintenant votre propre réseau ponté appelé **my-bridged-network** : | + | Cette commande stipule la commande qui sera exécutée lors du démarrage du conteneur. |
- | < | + | Deux cas de figure se présentent |
- | root@debian9:~# docker network create -d bridge --subnet 172.25.0.0/ | + | |
- | ceb7ba7493933c55d181bc92b1f799ca07bfe84b168d52a6ac648c1a906093f3 | + | |
- | root@debian9: | + | |
- | NETWORK ID NAME | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | ceb7ba749393 | + | |
- | 6bda460c97c6 | + | |
- | </ | + | |
- | Bien évidement, ce réseau | + | * ENTRYPOINT suivi d'une chaîne - un shell est démarré pour exécuter la chaîne, |
+ | * ENTRYPOINT suivi d'une table JSON ( comme ci-dessus ) au format ENTRYPOINT [" | ||
- | < | + | Dans le fichier **docker-entrypoint.sh** : |
- | root@debian9: | + | |
- | [ | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | </ | + | |
- | Lancez maintenant deux conteneurs et consultez les informations concernant le réseau : | + | < |
+ | ... | ||
+ | originalArgOne=" | ||
- | < | + | # allow the container to be started with `--user` |
- | root@debian9: | + | # all mongo* commands should be dropped to the correct user |
- | 9f36a628c72b383edfd4dc13ee4e4b2eaf5be0078d780f0334fcb8be0d977d0e | + | if [[ " |
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
- | root@debian9: | + | # make sure we can write to stdout and stderr as " |
- | aaed3bc8e404ee1bccd6c87b39de32332940b5391514691fc70188edb17c1d7c | + | # (for our " |
+ | chown | ||
+ | # ignore errors thanks to https:// | ||
- | root@debian9: | + | exec gosu mongodb |
- | {"bridge":{"IPAMConfig": | + | fi |
- | root@debian9:~# docker inspect | + | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. |
- | {" | + | # https:// |
+ | if [[ " | ||
+ | numa='numactl --interleave=all' | ||
+ | if $numa true &> /dev/null; then | ||
+ | set -- $numa "$@" | ||
+ | fi | ||
+ | fi | ||
+ | ... | ||
+ | exec "$@" | ||
+ | </ | ||
- | root@debian9: | + | si la valeur du paramètre passé à entrypoint.sh est **mongod**, le script affecte l'utilisateur mongodb aux répertoires / |
- | 172.17.0.3 | + | |
- | root@debian9:~# docker inspect --format='{{range | + | 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. |
- | 172.17.0.4 | + | |
- | </ | + | |
- | Mettez le conteneur | + | <WRAP center round important> |
+ | **Important** - Notez que la compilation d'une image se fait à l' | ||
+ | </ | ||
- | < | + | ====1.8 |
- | root@debian9: | + | |
- | root@debian9: | + | < |
- | [ | + | ... |
- | { | + | EXPOSE 27017 |
- | " | + | ... |
- | " | + | </file> |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | root@debian9: | + | Cette commande permet d'exposer un port à l'extérieur du conteneur. |
- | 172.17.0.3172.25.0.2 | + | |
- | </ | + | |
- | <WRAP center round important> | + | ====1.9 - CMD==== |
- | **Important** : Notez que le conteneur **centos1** se trouve dans deux réseaux. | + | |
- | </ | + | |
- | Faites la même chose pour le conteneur **centos2** : | + | < |
+ | ... | ||
+ | CMD [" | ||
+ | ... | ||
+ | </ | ||
- | < | + | Ceci représente la valeur du paramètre par défaut si aucun paramètre n'est spécifié à la fin de la commande |
- | root@debian9: | + | |
- | root@debian9: | + | ====1.10 |
- | [ | + | |
- | { | + | Le Dockerfile peut aussi contenir les commandes suivantes |
- | " | + | |
- | " | + | * **WORKDIR**, |
- | " | + | * Cette commande fixe le répertoire de travil lors de la compilation d'une image. Elle peut apparaître plusieurs fois dans le Dockerfile permettant ainsi l' |
- | " | + | * **LABEL**, |
- | " | + | * Cette commande permet de définir des couples clef/valeur à inclure dans les méta-données décrivant l' |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | root@debian9: | ||
- | 172.17.0.4172.25.0.3 | ||
- | </ | ||
- | Connectez-vous au conteneur **centos1** en lançant bash : | + | Lancez maintenant la compilation de l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
</ | </ | ||
- | Vérifiez que la connectivité fonctionne | + | Consultez |
< | < | ||
- | [root@9f36a628c72b | + | root@debian9:~/mongodb# docker images |
- | PING 172.25.0.3 (172.25.0.3) 56(84) bytes of data. | + | REPOSITORY |
- | 64 bytes from 172.25.0.3: icmp_seq=1 ttl=64 time=0.100 ms | + | < |
- | 64 bytes from 172.25.0.3: icmp_seq=2 ttl=64 time=0.050 ms | + | i2tch/ |
- | 64 bytes from 172.25.0.3: icmp_seq=3 ttl=64 time=0.050 ms | + | nginx |
- | ^C | + | centos |
- | --- 172.25.0.3 ping statistics --- | + | ubuntu |
- | 3 packets transmitted, | + | ubuntu |
- | rtt min/ | + | hello-world |
</ | </ | ||
- | Les options possibles au niveau de la gestion du réseau sont vaste. Voici deux exemples supplémentaires. | + | Notez que l'image n'a ni REPOSITORY, ni TAG. Créez donc un TAG : |
- | + | ||
- | Il est possible d'ajouter une adresse d'un serveur DNS au lancement d' | + | |
< | < | ||
- | [root@9f36a628c72b /]# exit | + | root@debian9: |
- | exit | + | root@debian9: |
- | root@debian9: | + | REPOSITORY |
- | mongo2 | + | i2tch/mongodb1 |
- | root@debian9: | + | i2tch/mongodb |
- | mongo2 | + | nginx |
- | root@debian9: | + | centos |
- | root@735599480b45:/# | + | ubuntu |
- | search home | + | ubuntu |
- | nameserver 8.8.8.8 | + | hello-world |
- | root@735599480b45:/# | + | |
</ | </ | ||
- | ou de passer une entrée pour le fichier **/etc/ | + | Démarrez un conteneur à partir |
< | < | ||
- | root@735599480b45:/# | + | root@debian9: |
- | exit | + | bdb4bc0f81de8b5821f20d8609b9640abaaae7b4a7577c42b78d4bd34617d211 |
- | root@debian9: | + | docker: Error response from daemon: oci runtime error: container_linux.go: |
- | mongo2 | + | root@debian9: |
- | root@debian9:~# docker | + | total 16 |
- | mongo2 | + | -rw-r--r-- 1 root root 10971 avril 9 13:56 docker-entrypoint.sh |
- | root@debian9: | + | -rw-r--r-- 1 root root 3542 avril 9 13:55 Dockerfile |
- | root@718e7eab814f:/# cat / | + | |
- | 127.0.0.1 localhost | + | |
- | :: | + | |
- | fe00::0 ip6-localnet | + | |
- | ff00::0 ip6-mcastprefix | + | |
- | ff02::1 ip6-allnodes | + | |
- | ff02::2 ip6-allrouters | + | |
- | 127.0.0.1 mickeymouse | + | |
- | 172.17.0.2 718e7eab814f | + | |
</ | </ | ||
- | ====Host==== | + | <WRAP center round important> |
- | + | **Important** - Notez que le fichier docker-entrypoint.sh n'était pas exécutable ! | |
- | Ce type de réseau est utilisé dans le cas où le réseau ne doit pas être isolé de l' | + | </ |
- | Dans le cas de la machine virtuelle, | + | Recompilez donc l'image : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 2: enp0s3: < | + | mongo1 |
- | link/ether 08:00:27:2e:77:01 brd ff:ff:ff:ff:ff:ff | + | root@debian9:~/mongodb# chmod +x docker-entrypoint.sh |
- | inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3 | + | root@debian9:~/mongodb# docker build . |
- | valid_lft 83772sec preferred_lft 83772sec | + | Sending build context to Docker daemon |
- | inet6 fe80::a00:27ff:fe2e:7701/64 scope link | + | Step 1/22 : FROM ubuntu:bionic |
- | valid_lft forever preferred_lft forever | + | |
+ | Step 2/22 : RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | ||
+ | | ||
+ | | ||
+ | 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 / | ||
+ | ---> Using cache | ||
+ | | ||
+ | Step 4/22 : ENV GOSU_VERSION 1.11 | ||
+ | | ||
+ | | ||
+ | Step 5/22 : ENV JSYAML_VERSION 3.13.0 | ||
+ | | ||
+ | | ||
+ | ... | ||
+ | Removing intermediate container a98ae692fe1f | ||
+ | ---> 04c2e98927c3 | ||
+ | Step 17/22 : RUN mkdir -p /data/db / | ||
+ | | ||
+ | Removing intermediate container d0f5bee34571 | ||
+ | | ||
+ | Step 18/22 : VOLUME /data/db / | ||
+ | | ||
+ | Removing intermediate container c7626528a9b9 | ||
+ | | ||
+ | Step 19/22 : COPY docker-entrypoint.sh / | ||
+ | | ||
+ | Step 20/22 : ENTRYPOINT [" | ||
+ | | ||
+ | Removing intermediate container eff53d0213d1 | ||
+ | | ||
+ | Step 21/22 : EXPOSE 27017 | ||
+ | ---> Running in 5139fcf19d7f | ||
+ | Removing intermediate container 5139fcf19d7f | ||
+ | | ||
+ | Step 22/22 : CMD [" | ||
+ | | ||
+ | Removing intermediate container 458d6f15cdf2 | ||
+ | | ||
+ | Successfully built 12e00099ca8d | ||
+ | root@debian9: | ||
</ | </ | ||
- | Démarrez | + | <WRAP center round important> |
+ | **Important** - Notez ici les lignes **Using cache**. Il est cependant possible de ne pas utiliser le cache en stipulant **--no-cache**. Notez aussi l' | ||
+ | </ | ||
+ | |||
+ | Consultez la liste des images de nouveau et renommez votre dernière image : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [root@debian9 /]# ip a | + | REPOSITORY |
- | 1: lo: <LOOPBACK, | + | <none> < |
- | link/loopback 00: | + | i2tch/mongodb1 |
- | inet 127.0.0.1/8 scope host lo | + | i2tch/mongodb |
- | | + | nginx |
- | inet6 ::1/128 scope host | + | centos |
- | valid_lft forever preferred_lft forever | + | ubuntu |
- | 2: enp0s3: < | + | ubuntu |
- | | + | hello-world |
- | inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3 | + | root@debian9: |
- | valid_lft 82102sec preferred_lft 82102sec | + | root@debian9:~/mongodb# docker images |
- | inet6 fe80:: | + | REPOSITORY |
- | valid_lft forever preferred_lft forever | + | i2tch/mongodb2 |
- | 3: docker0: < | + | i2tch/mongodb1 |
- | link/ether 02: | + | i2tch/ |
- | inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 | + | nginx |
- | valid_lft forever preferred_lft forever | + | centos |
- | inet6 fe80:: | + | ubuntu |
- | valid_lft forever preferred_lft forever | + | ubuntu |
- | [root@debian9 /]# hostname | + | hello-world |
- | debian9 | + | |
- | [root@debian9 /]# exit | + | |
</ | </ | ||
- | ====None==== | + | Lancez un conteneur à partir de la dernière image : |
- | Ce type de réseau est utilisé principalement dans le cas de l' | + | < |
+ | root@debian9:~/mongodb# | ||
+ | e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a | ||
+ | </code> | ||
- | Il est donc possible de lancer un conteneur totalement étanche grâce au réseau | + | Utilisez la commande |
< | < | ||
- | root@718e7eab814f:/# | + | root@debian9: |
- | exit | + | CONTAINER ID IMAGE |
- | root@debian9: | + | e91a055283f4 |
- | mongo2 | + | d2ddb4f8ca8a |
- | root@debian9: | + | c080793965de |
- | mongo2 | + | |
- | root@debian9: | + | |
- | root@332aa9930f30:/# | + | |
</ | </ | ||
- | ====Liens==== | + | Connectez-vous |
- | + | ||
- | Le mécanisme des liens entre conteneurs est très puissant et permet d' | + | |
< | < | ||
- | root@332aa9930f30:/# exit | + | root@debian9:~/mongodb# docker inspect mongo2 | grep IP |
- | exit | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | MongoDB shell version v4.0.8 | ||
+ | connecting to: mongodb:// | ||
+ | Implicit session: session { " | ||
+ | MongoDB server version: 4.1.9 | ||
+ | WARNING: shell and server versions do not match | ||
+ | Server has startup warnings: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | --- | ||
+ | Enable MongoDB' | ||
+ | metrics about your deployment (disk utilization, | ||
- | root@debian9: | + | The monitoring data will be available on a MongoDB website with a unique URL accessible to you |
- | 6a315259b2946c3bf2bb69f608cbe910d87edaadedb4f805e7a4dbf6af1eb916 | + | and anyone you share the URL with. MongoDB may use this information to make product |
+ | improvements and to suggest MongoDB products and deployment options to you. | ||
- | root@debian9:~# docker ps -a | + | To enable free monitoring, run the following command: db.enableFreeMonitoring() |
- | CONTAINER ID IMAGE | + | To permanently disable this reminder, run the following command: db.disableFreeMonitoring() |
- | 6a315259b294 | + | --- |
- | 332aa9930f30 | + | |
- | aaed3bc8e404 | + | |
- | 9f36a628c72b | + | |
- | 2169360fcbfd | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9: | + | > exit |
+ | bye | ||
+ | root@debian9: | ||
+ | </ | ||
- | [root@6a315259b294 /]# ping centos2 | + | Notez que lors de la compilation de l' |
- | PING alias (172.17.0.4) 56(84) bytes of data. | + | |
- | 64 bytes from alias (172.17.0.4): icmp_seq=1 ttl=64 time=0.116 ms | + | |
- | 64 bytes from alias (172.17.0.4): | + | |
- | 64 bytes from alias (172.17.0.4): | + | |
- | 64 bytes from alias (172.17.0.4): | + | |
- | ^C | + | |
- | --- alias ping statistics --- | + | |
- | 4 packets transmitted, | + | |
- | rtt min/ | + | |
- | [root@6a315259b294 | + | < |
- | 127.0.0.1 localhost | + | root@debian9:~/mongodb# docker images -a |
- | ::1 localhost ip6-localhost ip6-loopback | + | REPOSITORY |
- | fe00:: | + | i2tch/mongodb2 |
- | ff00:: | + | < |
- | ff02:: | + | < |
- | ff02:: | + | < |
- | 172.17.0.4 alias aaed3bc8e404 centos2 | + | < |
- | 172.17.0.2 6a315259b294 | + | < |
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/mongodb1 | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/ | ||
+ | < | ||
+ | < | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </ | ||
- | [root@6a315259b294 /]# exit | + | =====LAB |
- | exit | + | |
- | root@debian9: | + | ====2.1 - Création et test du script==== |
- | 172.17.0.2 | + | |
- | </ | + | |
- | Notez cependant qu le lien est unidirectionnel | + | Créez un répertoire nommé myDocker |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | </ | ||
- | [root@aaed3bc8e404 /]# ping centos3 | + | Créez le fichier myEntrypoint.sh |
- | ping: centos3: Name or service not known | + | |
- | [root@aaed3bc8e404 | + | < |
- | PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data. | + | root@debian9:~/myDocker# vi myEntrypoint.sh |
- | 64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.054 ms | + | root@debian9:~/myDocker# cat myEntrypoint.sh |
- | 64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.035 ms | + | #!/bin/bash |
- | 64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.051 ms | + | if [ -z " |
- | 64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.071 ms | + | echo "La variable myVariable doit être renseignée" |
- | ^C | + | return 1 |
- | --- 172.17.0.2 ping statistics --- | + | fi |
- | 4 packets transmitted, | + | |
- | rtt min/ | + | |
- | [root@aaed3bc8e404 /]# | + | while true; |
+ | do | ||
+ | echo $1 \($(date +%H: | ||
+ | sleep " | ||
+ | done | ||
</ | </ | ||
- | Dans le cas ci-dessus, **centos2** peut atteindre **centos3** en utilisant l' | + | Testez ce script |
< | < | ||
- | [root@aaed3bc8e404 | + | root@debian9:~/myDocker# myVariable=3 . ./ |
- | exit | + | salut (20: |
- | root@debian9: | + | salut (20: |
- | 172.17.0.4172.25.0.3 | + | salut (20: |
+ | salut (20: | ||
+ | salut (20: | ||
+ | ^C | ||
+ | root@debian9: | ||
</ | </ | ||
- | ====Lancer Wordpress dans un container==== | + | Rendez ce script exécutable |
- | + | ||
- | Créez le répertoire ~/wordpress et placez-vous dedans | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
</ | </ | ||
- | Créez | + | Créez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Unable to find image ' | + | root@debian9:~/myDocker# cat Dockerfile |
- | latest: Pulling from library/mariadb | + | FROM centos:latest |
- | f2b6b4884fc8: | + | MAINTAINER i2tch " |
- | 26d8bdca4f3e: | + | COPY myEntrypoint.sh |
- | 74f09e820cce: | + | ENV myVariable 3 |
- | 5390f1fe4554: | + | ENTRYPOINT ["/ |
- | 3d3f1706a741: | + | CMD [" |
- | 2942f66426ea: | + | |
- | 97ee11d39c75: | + | |
- | 590c46ef722b: | + | |
- | 32eb4b9666e5: | + | |
- | fc883f98a064: | + | |
- | bb8bee61bc1e: | + | |
- | Digest: sha256: | + | |
- | Status: Downloaded newer image for mariadb: | + | |
- | 67831dacf002bdc21dc79b0e8483f538235d00ddd2e8aae175ef3ebf189ae14d | + | |
</ | </ | ||
- | Vérifiez que le conteneur fonctionne | + | Générez maintenant l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER ID IMAGE | + | Sending build context to Docker daemon |
- | 67831dacf002 | + | Step 1/6 : FROM centos:latest |
+ | | ||
+ | Step 2/6 : MAINTAINER i2tch "infos@i2tch.eu" | ||
+ | ---> Running in 02c700ed04da | ||
+ | Removing intermediate container 02c700ed04da | ||
+ | | ||
+ | Step 3/6 : COPY myEntrypoint.sh /entrypoint.sh | ||
+ | | ||
+ | Step 4/6 : ENV myVariable 3 | ||
+ | | ||
+ | Removing intermediate container 3288bf6291ad | ||
+ | | ||
+ | Step 5/6 : ENTRYPOINT ["/entrypoint.sh" | ||
+ | | ||
+ | Removing intermediate container 8dcba2c41520 | ||
+ | | ||
+ | Step 6/6 : CMD [" | ||
+ | | ||
+ | Removing intermediate container f891fbcfaad0 | ||
+ | | ||
+ | Successfully built 7925ba23abb2 | ||
+ | Successfully tagged i2tch/ | ||
</ | </ | ||
- | Créez un conteneur | + | Lancez le conteneur : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Unable to find image ' | + | mycommand (18:07:12) |
- | latest: Pulling from library/ | + | mycommand (18:07:15) |
- | 2a72cbf407d6: Pull complete | + | mycommand (18:07:18) |
- | 273cd543cb15: Pull complete | + | mycommand (18:07:21) |
- | ec5ac8875de7: Pull complete | + | ^Cmycommand (18:07:22) |
- | 9106e19b56c1: Pull complete | + | mycommand (18:07:25) |
- | ee2f70ac7c7d: Pull complete | + | mycommand (18:07:28) |
- | 7257ad6985e8: Pull complete | + | ^P^Q |
- | 18f5c2055da2: Pull complete | + | root@debian9:~/myDocker# |
- | 85293a6fdd80: Pull complete | + | |
- | 9e797eeb0c14: Pull complete | + | |
- | f16178842884: Pull complete | + | |
- | 13899c06d3f8: Pull complete | + | |
- | 70c27fe4c3c5: Pull complete | + | |
- | d32c8ad2d9d7: | + | |
- | 07fe445494e6: Pull complete | + | |
- | 63b8de7b32fe: | + | |
- | e4b721952e22: | + | |
- | d9ede6dd6f74: | + | |
- | 0af4f74bfd92: | + | |
- | e4e7c47b969f: | + | |
- | 69aff47f3112: | + | |
- | Digest: sha256: | + | |
- | Status: Downloaded newer image for wordpress: | + | |
- | 9eb2f7fbfbd25307ed2f463c7eb3bef40bfa556174e68750bb76b8d032546129 | + | |
</ | </ | ||
- | Vérifiez | + | Constatez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER ID IMAGE | + | CONTAINER ID IMAGE |
- | 9eb2f7fbfbd2 | + | 140ecfdd80b7 |
- | 67831dacf002 | + | b3380889eb75 |
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18:08:52) | ||
</ | </ | ||
- | Vérifiez que le Wordpress fonctionne | + | Arrêtez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | | + | myDocker |
- | Select a default language [English (United States)________] | + | root@debian9:~/myDocker# docker ps |
+ | CONTAINER ID IMAGE | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | </ | ||
- | | + | Démarrez le conteneur : |
- | References | + | < |
+ | root@debian9: | ||
+ | myDocker | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | </ | ||
- | 1. https:// | + | Mettez le conteneur en pause : |
- | root@debian9: | + | < |
- | " | + | root@debian9: |
- | "IPAddress": "172.17.0.3", | + | myDocker |
- | "IPAddress": "172.17.0.3", | + | root@debian9:~/myDocker# docker ps |
- | + | CONTAINER ID IMAGE | |
- | root@debian9:~/ | + | 140ecfdd80b7 |
- | | + | b3380889eb75 |
- | Select a default language [English (United States)________] | + | d2ddb4f8ca8a |
+ | c080793965de | ||
+ | </ | ||
- | | + | Supprimez la pause : |
- | References | + | < |
- | + | root@debian9: | |
- | 1. https://wordpress.org/ | + | myDocker |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
</ | </ | ||
- | ====Gestion d'une Architecture de Microservices==== | + | Lancez maintenant le conteneur avec un paramètre : |
- | Vous allez mettre en place une application simple sous forme de microservices, | + | < |
+ | root@debian9: | ||
+ | myDocker | ||
+ | root@debian9: | ||
+ | 0cf8c8c1bdf4cb05d9852900ecdf171ad9abad0fce29a9f040d5d8436285db65 | ||
+ | root@debian9: | ||
+ | Up and Running (18: | ||
+ | Up and Running (18: | ||
+ | Up and Running (18: | ||
+ | Up and Running (18: | ||
+ | root@debian9:~/myDocker# | ||
+ | </ | ||
- | {{ :elearning: | + | Changez la valeur de la variable d' |
- | Dans cette application le conteneur **voting-app** permet de voter pour des **chats** ou des **chiens**. Cette application tourne sous Python et fournit une interface HTML : | + | < |
- | + | root@debian9: | |
- | {{ :elearning:workbooks:debian:6:avance:kubernetes15.png? | + | myDocker |
- | + | root@debian9:~/myDocker# docker run -d --name myDocker --env myVariable=1 i2tch/ | |
- | Lors de la vote, le résultat de celle-ci est stocké dans **Redis** dans une base de données en mémoire. Le résultat est ensuite passé au conteneur **Worker** qui tourne sous .NET et qui met à jour la base de données persistante dans le conteneur **db** qui tourne sous PostgreSQL. | + | fbbe3b48c63310e37a3bad5fc962361c39c045a107f47980614efd6b2e8d3981 |
+ | root@debian9:~/myDocker# docker logs myDocker | ||
+ | mycommand (18:14:47) | ||
+ | mycommand (18:14:48) | ||
+ | mycommand (18:14:49) | ||
+ | mycommand (18:14:50) | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | root@debian9: | ||
+ | </ | ||
- | L' | + | ====2.2 |
- | {{ : | + | ===Opérations Non-Idempotentes=== |
- | Cette application peut être mise en place sous docker avec les commandes suivantes | + | Créez un répertoire **bestp** ainsi que le fichier Dockerfile suivant |
< | < | ||
- | docker run -d --name=redis redis | + | root@debian9:~/myDocker# cd .. |
- | docker run -d --name=db postgres:9.4 | + | root@debian9:~# mkdir bestp |
- | docker run -d --name=vote -p 5000:80 --link redis:redis dockersamples/examplevotingapp_vote | + | root@debian9:~# cd bestp |
- | docker run -d --name=result -p 5001:80 --link db:db dockersamples/examplevotingapp_result | + | root@debian9: |
- | docker run -d --name=worker --link db:db --link redis:redis dockersamples/examplevotingapp_worker | + | root@debian9:~/bestp# cat Dockerfile |
+ | FROM ubuntu:latest | ||
+ | RUN date +%N > / | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/tmp/moment" | ||
</ | </ | ||
- | Cette solution utilise un réseau de type Bridge. Ce type de réseau est limité aux conteneurs d'un hôte unique exécutant Docker. Les conteneurs ne peuvent communiquer qu' | + | Le fichier Dokerfile contient une opération non idempotente. |
+ | <WRAP center round important> | ||
+ | **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. | ||
+ | </ | ||
- | =====LAB #8 - Superviser les Conteneurs===== | + | Compilez l' |
- | ====Les Journaux==== | + | < |
+ | root@debian9: | ||
+ | Sending build context to Docker daemon | ||
+ | Step 1/4 : FROM ubuntu: | ||
+ | | ||
+ | Step 2/4 : RUN date +%N > / | ||
+ | | ||
+ | Removing intermediate container 6c8c677c1549 | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT [" | ||
+ | | ||
+ | Removing intermediate container e9658e591172 | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | Removing intermediate container 48974dc12faa | ||
+ | | ||
+ | Successfully built c55a42a18572 | ||
+ | Successfully tagged testcache: | ||
+ | root@debian9: | ||
+ | </ | ||
- | Consultez les logs d'un conteneur : | + | Exécuter maintenant |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@332aa9930f30:/# | + | 369009216 |
- | bash: ip: command not found | + | |
- | root@332aa9930f30:/# | + | |
- | bash: ip: command not found | + | |
- | root@332aa9930f30:/# | + | |
- | bash: ifconfig: command not found | + | |
- | root@332aa9930f30:/# | + | |
- | bin boot core data dev docker-entrypoint-initdb.d entrypoint.sh | + | |
- | root@332aa9930f30:/# | + | |
- | root@332aa9930f30:/# | + | |
- | root@332aa9930f30: | + | |
- | bash: docker: command not found | + | |
- | root@332aa9930f30:/# | + | |
- | exit | + | |
</ | </ | ||
- | ====Les Processus==== | + | Supprimez maintenant le conteneur |
- | + | ||
- | Consultez les processus d' | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | UID | + | test1 |
- | root | + | root@debian9:~/bestp# docker build -t testcache . |
+ | Sending build context to Docker daemon | ||
+ | Step 1/4 : FROM ubuntu:latest | ||
+ | | ||
+ | Step 2/4 : RUN date +%N > /tmp/ | ||
+ | | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT [" | ||
+ | | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | | ||
+ | Successfully built c55a42a18572 | ||
+ | Successfully tagged testcache: | ||
+ | root@debian9: | ||
</ | </ | ||
- | ====L' | + | Lancez un conteneur à partir de l'image re-compilée |
- | + | ||
- | Pour voir l'activité d'un conteneur, utilisez la commande suivante | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER | + | 369009216 |
- | centos3 | + | |
</ | </ | ||
- | =====LAB #9 - Gestion | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | La gestion | + | Pour contourner ce problème, il est possible d' |
- | * --memory | + | < |
- | * --cpu-shares | + | root@debian9: |
+ | root@debian9: | ||
+ | FROM ubuntu: | ||
+ | RUN date +%N > /tmp/moment \ | ||
+ | && echo " | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/ | ||
+ | </ | ||
- | ====Limiter | + | Supprimez maintenant le conteneur et relancez |
- | + | ||
- | Par exemple, exécutez un conteneur à partir | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | fc8ce16b3ec86433662719ca1f710a0588951d4f4abb8d90159b5953f419eef7 | + | test1 |
+ | root@debian9: | ||
+ | Sending build context to Docker daemon | ||
+ | Step 1/4 : FROM ubuntu: | ||
+ | ---> 94e814e2efa8 | ||
+ | Step 2/4 : RUN date +%N > / | ||
+ | ---> Running in 3d2a5cee6ac8 | ||
+ | Removing intermediate container 3d2a5cee6ac8 | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT ["more"] | ||
+ | ---> Running in 88c0cec68659 | ||
+ | Removing intermediate container 88c0cec68659 | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | Removing intermediate container 82d2162bb701 | ||
+ | | ||
+ | Successfully built a54c4af89994 | ||
+ | Successfully tagged testcache: | ||
</ | </ | ||
- | Exécutez ensuite la commande **docker stats** pour visualiser la limite | + | Lancez un conteneur à partir |
< | < | ||
- | CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS | + | root@debian9: |
- | fc8ce16b3ec8 | + | 746997174 |
</ | </ | ||
- | <WRAP center round important> | + | ----- |
- | **Important** : Notez que la limite définie par **--memory** est une taille absolue tandis que la limite définie par **--cpu-shares** est relative. | + | |
- | </ | + | |
- | ----- | + | Copyright © 2022 Hugh Norris. |
- | < | + | |
- | <div align=" | + | |
- | Copyright © 2020 Hugh NORRIS | + | |
- | </ | + | |
- | </ | + |