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:48] – admin | elearning:workbooks:docker1:drf02 [2021/12/29 10:32] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version : **2020.02** - Consulter le ChangeLog en fin de module | + | 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 ' | ||
+ | } | ||
- | < | + | jsonConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-config.json" |
- | root@debian9: | + | tempConfigFile="${TMPDIR:-/tmp}/docker-entrypoint-temp-config.json" |
- | ... | + | _parse_config() { |
- | | + | if [ -s "$tempConfigFile" |
- | | + | return 0 |
- | " | + | fi |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Driver": " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ... | + | |
- | </ | + | |
- | <WRAP center round important> | + | local configPath |
- | **Important** : Notez ici que l' | + | if configPath=" |
- | </WRAP> | + | # 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 | ||
- | https:// | + | return 1 |
+ | } | ||
+ | dbPath= | ||
+ | _dbPath() { | ||
+ | if [ -n " | ||
+ | echo " | ||
+ | return | ||
+ | fi | ||
- | =====LAB #6 - Gestion du Réseau===== | + | if ! dbPath=" |
+ | if _parse_config " | ||
+ | dbPath=" | ||
+ | fi | ||
+ | fi | ||
- | Docker fournit trois réseaux par défaut | + | 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 | ||
- | < | + | : " |
- | root@debian9:~# docker network ls | + | |
- | NETWORK ID NAME DRIVER | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | 6bda460c97c6 | + | |
- | </code> | + | |
- | ====Bridge==== | + | echo " |
+ | } | ||
- | Ce type de réseau est limité aux conteneurs d'un hôte unique exécutant Docker. Les conteneurs ne peuvent communiquer qu'entre eux et ils ne sont pas accessibles depuis l'extérieur. Pour que les conteneurs sur le réseau puissent communiquer ou être accessibles du monde extérieur, il faut configurer le mappage de port. | + | if [ " |
+ | file_env | ||
+ | file_env ' | ||
+ | # pre-check a few factors to see if it's even worth bothering with initdb | ||
+ | shouldPerformInitdb= | ||
+ | if [ " | ||
+ | # if we have a username/ | ||
+ | _mongod_hack_ensure_arg ' | ||
+ | set -- " | ||
+ | shouldPerformInitdb=' | ||
+ | elif [ " | ||
+ | cat >&2 << | ||
+ | error: missing ' | ||
+ | both must be specified for a user to be created | ||
+ | EOF | ||
+ | exit 1 | ||
+ | fi | ||
- | Par défaut Docker fonctionne en mode **Pont** ou (//Bridge//) et crée une interface intermédiaire à cet effet appelé | + | if [ -z " |
+ | # if we've got any /docker-entrypoint-initdb.d/* files to parse later, we should initdb | ||
+ | for f in /docker-entrypoint-initdb.d/*; do | ||
+ | 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) |
- | root@debian9: | + | if [ -n " |
- | 3: docker0: <NO-CARRIER, | + | dbPath=" |
- | link/ether 02: | + | for path in \ |
- | inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 | + | " |
- | valid_lft forever preferred_lft forever | + | " |
- | </ | + | " |
+ | " | ||
+ | ; do | ||
+ | if [ -e " | ||
+ | shouldPerformInitdb= | ||
+ | break | ||
+ | fi | ||
+ | done | ||
+ | fi | ||
- | Démarrez un conteneur dénommé **resotest** à partir d'une image de CentOS : | + | 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 " |
- | root@debian9:~# docker | + | # https:// |
- | 2169360fcbfdbd6e68ea969a95edeb6fc42603c23ee42f03ceec286276519855 | + | _mongod_hack_ensure_no_arg |
- | </ | + | if [ " |
+ | _mongod_hack_ensure_no_arg_val --replSet " | ||
+ | fi | ||
- | Lancez ensuite la commande **docker network inspect bridge** à partir de la machine virtuelle hôte de Debian_9 | + | sslMode=" |
+ | _mongod_hack_ensure_arg_val --sslMode " | ||
- | < | + | if stat "/ |
- | root@debian9: | + | # https://github.com/ |
- | [ | + | # https://github.com/docker-library/ |
- | { | + | _mongod_hack_ensure_arg_val --logpath |
- | | + | else |
- | " | + | initdbLogPath="$(_dbPath |
- | " | + | echo >& |
- | " | + | _mongod_hack_ensure_arg_val --logpath |
- | " | + | fi |
- | " | + | _mongod_hack_ensure_arg --logappend |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | | + | |
- | " | + | |
- | } | + | |
- | | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "IPv6Address": "" | + | |
- | | + | |
- | }, | + | |
- | | + | |
- | " | + | |
- | "com.docker.network.bridge.enable_icc": "true", | + | |
- | "com.docker.network.bridge.enable_ip_masquerade": " | + | |
- | " | + | |
- | | + | |
- | "com.docker.network.driver.mtu": "1500" | + | |
- | }, | + | |
- | "Labels": | + | |
- | } | + | |
- | ] | + | |
- | </ | + | |
- | <WRAP center round important> | + | pidfile=" |
- | **Important** | + | rm -f "$pidfile" |
- | </ | + | _mongod_hack_ensure_arg_val --pidfilepath " |
- | Vous pouvez déconnecter un conteneur du réseau en utilisant la commande suivante : | + | " |
- | < | + | mongo=( mongo --host 127.0.0.1 |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | [ | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | </ | + | |
- | Créez maintenant votre propre réseau ponté appelé **my-bridged-network** | + | # 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 [ " |
- | root@debian9: | + | rootAuthDatabase=' |
- | ceb7ba7493933c55d181bc92b1f799ca07bfe84b168d52a6ac648c1a906093f3 | + | |
- | root@debian9: | + | |
- | NETWORK ID NAME | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | ceb7ba749393 | + | |
- | 6bda460c97c6 | + | |
- | </ | + | |
- | Bien évidement, ce réseau est actuellement vide : | + | " |
+ | db.createUser({ | ||
+ | user: $(_js_escape " | ||
+ | pwd: $(_js_escape " | ||
+ | roles: [ { role: ' | ||
+ | }) | ||
+ | EOJS | ||
+ | fi | ||
- | < | + | export MONGO_INITDB_DATABASE=" |
- | root@debian9: | + | |
- | [ | + | |
- | | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | </ | + | |
- | Lancez maintenant deux conteneurs et consultez les informations concernant le réseau | + | echo |
+ | for f in / | ||
+ | case " | ||
+ | *.sh) echo "$0: running $f"; . " | ||
+ | *.js) echo "$0: running $f"; " | ||
+ | *) | ||
+ | esac | ||
+ | echo | ||
+ | done | ||
- | < | + | " |
- | root@debian9:~# docker run -itd --name=centos1 centos | + | rm -f " |
- | 9f36a628c72b383edfd4dc13ee4e4b2eaf5be0078d780f0334fcb8be0d977d0e | + | |
- | root@debian9: | + | echo |
- | aaed3bc8e404ee1bccd6c87b39de32332940b5391514691fc70188edb17c1d7c | + | echo ' |
+ | echo | ||
+ | fi | ||
- | root@debian9: | + | # MongoDB 3.6+ defaults to localhost-only binding |
- | {"bridge":{"IPAMConfig": | + | if mongod |
+ | haveBindIp= | ||
+ | if _mongod_hack_have_arg --bind_ip | ||
+ | haveBindIp=1 | ||
+ | elif _parse_config | ||
+ | haveBindIp=1 | ||
+ | fi | ||
+ | if [ -z "$haveBindIp" | ||
+ | # so if no "--bind_ip" | ||
+ | set -- "$@" | ||
+ | fi | ||
+ | fi | ||
- | root@debian9:~# docker inspect --format=' | + | unset " |
- | {" | + | fi |
- | root@debian9: | + | rm -f " |
- | 172.17.0.3 | + | |
- | root@debian9:~# docker inspect --format=' | + | exec "$@" |
- | 172.17.0.4 | + | </file> |
- | </code> | + | |
- | Mettez le conteneur **centos1** | + | Examinons chaque commande |
- | < | + | ====1.2 |
- | root@debian9: | + | |
- | root@debian9: | + | < |
- | [ | + | FROM ubuntu:bionic |
- | { | + | </file> |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | root@debian9: | + | Cette ligne définit l' |
- | 172.17.0.3172.25.0.2 | + | |
- | </code> | + | ====1.3 |
+ | |||
+ | < | ||
+ | ... | ||
+ | |||
+ | RUN groupadd | ||
+ | |||
+ | RUN set -eux; \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | ca-certificates \ | ||
+ | jq \ | ||
+ | numactl \ | ||
+ | ; \ | ||
+ | if ! command -v ps > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends procps; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | ... | ||
+ | RUN set -ex; \ | ||
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver 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 /etc/mongod.conf /etc/mongod.conf.orig | ||
+ | |||
+ | 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 que le conteneur | + | **Important** : La commande RUN est utilisée pour exécuter une commande passée en argument lors de la compilation de l' |
</ | </ | ||
- | Faites la même chose pour le conteneur **centos2** : | + | ====1.4 - ENV==== |
- | < | + | Cette commande permet de fixer la valeur d'une variable d' |
- | root@debian9:~# docker network connect my-bridged-network centos2 | + | |
- | root@debian9: | + | < |
- | [ | + | ... |
- | { | + | ENV GOSU_VERSION 1.11 |
- | " | + | # grab "js-yaml" |
- | " | + | ENV JSYAML_VERSION 3.13.0 |
- | " | + | ... |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | "Gateway": | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | root@debian9: | + | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B |
- | 172.17.0.4172.25.0.3 | + | ... |
- | </ | + | |
- | Connectez-vous au conteneur **centos1** en lançant bash : | + | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} |
- | < | + | ENV MONGO_MAJOR 4.1 |
- | root@debian9: | + | ENV MONGO_VERSION 4.1.95 |
- | </code> | + | ... |
+ | </file> | ||
- | Vérifiez que la connectivité fonctionne : | + | **et** dans les conteneurs générés à partir de l' |
- | < | + | ====1.5 - VOLUME==== |
- | [root@9f36a628c72b /]# ping 172.25.0.3 | + | |
- | PING 172.25.0.3 (172.25.0.3) 56(84) bytes of data. | + | |
- | 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 | + | |
- | 64 bytes from 172.25.0.3: icmp_seq=3 ttl=64 time=0.050 ms | + | |
- | ^C | + | |
- | --- 172.25.0.3 ping statistics --- | + | |
- | 3 packets transmitted, | + | |
- | rtt min/ | + | |
- | </ | + | |
- | Les options possibles au niveau de la gestion du réseau sont vaste. Voici deux exemples supplémentaires. | + | < |
+ | ... | ||
+ | VOLUME /data/db / | ||
+ | ... | ||
+ | </ | ||
- | Il est possible d'ajouter une adresse d'un serveur DNS au lancement d'un conteneur : | + | 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'exemple nginx. |
- | < | + | ====1.6 |
- | [root@9f36a628c72b /]# exit | + | |
- | exit | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | root@735599480b45:/# | + | |
- | search home | + | |
- | nameserver 8.8.8.8 | + | |
- | root@735599480b45:/# | + | |
- | </ | + | |
- | ou de passer une entrée pour le fichier **/etc/hosts** : | + | < |
+ | ... | ||
+ | COPY docker-entrypoint.sh | ||
+ | ... | ||
+ | </ | ||
- | < | + | Cette commande permet de récupérer les fichiers dans le contexte et de les copier dans l' |
- | root@735599480b45:/# | + | |
- | exit | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | root@718e7eab814f:/# | + | |
- | 127.0.0.1 localhost | + | |
- | :: | + | |
- | fe00:: | + | |
- | ff00:: | + | |
- | ff02:: | + | |
- | ff02:: | + | |
- | 127.0.0.1 mickeymouse | + | |
- | 172.17.0.2 718e7eab814f | + | |
- | </ | + | |
- | ====Host==== | + | **Attention** : tous les fichiers dans le contexte sont inclus dans l' |
- | Ce type de réseau | + | Il est possible d' |
- | Dans le cas de la machine virtuelle, l' | + | <WRAP center round important> |
+ | **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 | ||
+ | </ | ||
- | < | + | ====1.7 - ENTRYPOINT==== |
- | root@debian9: | + | |
- | 2: enp0s3: < | + | |
- | link/ether 08: | + | |
- | inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3 | + | |
- | | + | |
- | inet6 fe80:: | + | |
- | | + | |
- | </ | + | |
- | Démarrez un conteneur à partir de l' | + | < |
+ | ... | ||
+ | ENTRYPOINT [" | ||
+ | ... | ||
+ | </ | ||
- | < | + | Cette commande stipule la commande qui sera exécutée lors du démarrage du conteneur. |
- | root@debian9: | + | |
- | [root@debian9 /]# ip a | + | |
- | 1: lo: < | + | |
- | link/ | + | |
- | inet 127.0.0.1/8 scope host lo | + | |
- | | + | |
- | inet6 ::1/128 scope host | + | |
- | | + | |
- | 2: enp0s3: < | + | |
- | link/ether 08: | + | |
- | inet 10.0.2.15/ | + | |
- | | + | |
- | inet6 fe80:: | + | |
- | | + | |
- | 3: docker0: < | + | |
- | link/ether 02: | + | |
- | inet 172.17.0.1/ | + | |
- | | + | |
- | inet6 fe80:: | + | |
- | | + | |
- | [root@debian9 /]# hostname | + | |
- | debian9 | + | |
- | [root@debian9 /]# exit | + | |
- | </ | + | |
- | ====None==== | + | Deux cas de figure se présentent : |
- | Ce type de réseau est utilisé principalement dans le cas de l' | + | * ENTRYPOINT suivi d'une chaîne - un shell est démarré pour exécuter la chaîne, |
+ | | ||
- | Il est donc possible de lancer un conteneur totalement étanche grâce au réseau | + | Dans le fichier |
- | <code> | + | <file> |
- | root@718e7eab814f:/# | + | ... |
- | exit | + | originalArgOne=" |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | root@332aa9930f30:/# | + | |
- | </ | + | |
- | ====Liens==== | + | # allow the container to be started with `--user` |
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
- | Le mécanisme des liens entre conteneurs est très puissant et permet d' | + | # make sure we can write to stdout and stderr as " |
+ | # (for our " | ||
+ | chown --dereference mongodb "/ | ||
+ | # ignore errors thanks to https:// | ||
- | < | + | exec gosu mongodb " |
- | root@332aa9930f30:/# | + | fi |
- | exit | + | |
- | root@debian9:~# docker run -itd --name centos3 | + | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. |
- | 6a315259b2946c3bf2bb69f608cbe910d87edaadedb4f805e7a4dbf6af1eb916 | + | # https:// |
+ | if [[ " | ||
+ | numa=' | ||
+ | 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' |
- | CONTAINER ID IMAGE | + | |
- | 6a315259b294 | + | |
- | 332aa9930f30 | + | |
- | aaed3bc8e404 | + | |
- | 9f36a628c72b | + | |
- | 2169360fcbfd | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9:~# docker exec -it centos3 bash | + | 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. |
- | [root@6a315259b294 /]# ping centos2 | + | <WRAP center round important> |
- | PING alias (172.17.0.4) 56(84) bytes of data. | + | **Important** - Notez que la compilation d'une image se fait à l' |
- | 64 bytes from alias (172.17.0.4): | + | </WRAP> |
- | 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/avg/ | + | |
- | [root@6a315259b294 /]# cat / | + | ====1.8 - EXPOSE==== |
- | 127.0.0.1 localhost | + | |
- | :: | + | |
- | fe00:: | + | |
- | ff00:: | + | |
- | ff02:: | + | |
- | ff02:: | + | |
- | 172.17.0.4 alias aaed3bc8e404 centos2 | + | |
- | 172.17.0.2 6a315259b294 | + | |
- | [root@6a315259b294 /]# exit | + | < |
- | exit | + | ... |
+ | EXPOSE 27017 | ||
+ | ... | ||
+ | </ | ||
- | root@debian9: | + | Cette commande permet d' |
- | 172.17.0.2 | + | |
+ | ====1.9 | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | CMD [" | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Ceci représente la valeur du paramètre par défaut si aucun paramètre n'est spécifié à la fin de la commande docker run. | ||
+ | |||
+ | ====1.10 - Autres Commandes==== | ||
+ | |||
+ | Le Dockerfile peut aussi contenir les commandes suivantes : | ||
+ | |||
+ | * **WORKDIR**, | ||
+ | * Cette commande fixe le répertoire de travil lors de la compilation d'une image. Elle peut apparaître plusieurs fois dans le Dockerfile permettant ainsi l' | ||
+ | * **LABEL**, | ||
+ | * Cette commande permet de définir des couples clef/valeur à inclure dans les méta-données décrivant l' | ||
+ | |||
+ | |||
+ | Lancez maintenant la compilation de l' | ||
+ | |||
+ | < | ||
+ | root@debian9: | ||
</ | </ | ||
- | Notez cependant qu le lien est unidirectionnel | + | Consultez la liste de images |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | REPOSITORY | ||
+ | < | ||
+ | i2tch/ | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </ | ||
- | [root@aaed3bc8e404 /]# ping centos3 | + | Notez que l' |
- | 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:~/mongodb# docker tag 3bf2 i2tch/ |
- | 64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.054 ms | + | root@debian9: |
- | 64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.035 ms | + | REPOSITORY |
- | 64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.051 ms | + | i2tch/ |
- | 64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.071 ms | + | i2tch/ |
- | ^C | + | nginx |
- | --- 172.17.0.2 ping statistics --- | + | centos |
- | 4 packets transmitted, | + | ubuntu |
- | rtt min/avg/ | + | ubuntu |
+ | hello-world | ||
+ | </code> | ||
- | [root@aaed3bc8e404 | + | Démarrez un conteneur à partir de l' |
+ | |||
+ | < | ||
+ | root@debian9:~/mongodb# docker run -d --name mongo1 i2tch/ | ||
+ | bdb4bc0f81de8b5821f20d8609b9640abaaae7b4a7577c42b78d4bd34617d211 | ||
+ | docker: Error response from daemon: oci runtime error: container_linux.go: | ||
+ | root@debian9: | ||
+ | total 16 | ||
+ | -rw-r--r-- 1 root root 10971 avril 9 13:56 docker-entrypoint.sh | ||
+ | -rw-r--r-- 1 root root 3542 avril 9 13:55 Dockerfile | ||
</ | </ | ||
- | Dans le cas ci-dessus, | + | <WRAP center round important> |
+ | **Important** - Notez que le fichier docker-entrypoint.sh n' | ||
+ | </ | ||
+ | |||
+ | Recompilez donc l'image : | ||
< | < | ||
- | [root@aaed3bc8e404 | + | root@debian9:~/mongodb# docker rm mongo1 |
- | exit | + | mongo1 |
- | root@debian9: | + | root@debian9: |
- | 172.17.0.4172.25.0.3 | + | root@debian9: |
+ | Sending build context to Docker daemon | ||
+ | Step 1/22 : FROM ubuntu: | ||
+ | | ||
+ | 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 / | ||
+ | | ||
+ | | ||
+ | Step 4/22 : ENV GOSU_VERSION 1.11 | ||
+ | | ||
+ | | ||
+ | Step 5/22 : ENV JSYAML_VERSION 3.13.0 | ||
+ | | ||
+ | | ||
+ | ... | ||
+ | Removing intermediate container a98ae692fe1f | ||
+ | | ||
+ | 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 | ||
+ | | ||
+ | Removing intermediate container 5139fcf19d7f | ||
+ | | ||
+ | Step 22/22 : CMD [" | ||
+ | | ||
+ | Removing intermediate container 458d6f15cdf2 | ||
+ | | ||
+ | Successfully built 12e00099ca8d | ||
+ | root@debian9: | ||
</ | </ | ||
- | ====Lancer Wordpress dans un container==== | + | <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' | ||
+ | </ | ||
- | Créez le répertoire ~/ | + | Consultez la liste des images de nouveau |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | REPOSITORY | ||
+ | < | ||
+ | i2tch/ | ||
+ | i2tch/ | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | i2tch/ | ||
+ | i2tch/ | ||
+ | i2tch/ | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Créez | + | Lancez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Unable to find image ' | + | e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a |
- | latest: Pulling from library/ | + | |
- | f2b6b4884fc8: | + | |
- | 26d8bdca4f3e: | + | |
- | 74f09e820cce: | + | |
- | 5390f1fe4554: | + | |
- | 3d3f1706a741: | + | |
- | 2942f66426ea: | + | |
- | 97ee11d39c75: | + | |
- | 590c46ef722b: | + | |
- | 32eb4b9666e5: | + | |
- | fc883f98a064: | + | |
- | bb8bee61bc1e: | + | |
- | Digest: sha256: | + | |
- | Status: Downloaded newer image for mariadb: | + | |
- | 67831dacf002bdc21dc79b0e8483f538235d00ddd2e8aae175ef3ebf189ae14d | + | |
</ | </ | ||
- | Vérifiez que le conteneur fonctionne | + | Utilisez la commande **docker ps** pour visualiser si le processus mongodb est bien démarré |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER ID IMAGE | + | CONTAINER ID IMAGE |
- | 67831dacf002 | + | e91a055283f4 |
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
</ | </ | ||
- | Créez un conteneur appellé **wordpress** lié au conteneur wordpressdb | + | Connectez-vous à mongodb à partir de votre machine hôte : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Unable to find image ' | + | " |
- | latest: Pulling from library/ | + | " |
- | 2a72cbf407d6: Pull complete | + | " |
- | 273cd543cb15: Pull complete | + | " |
- | ec5ac8875de7: Pull complete | + | |
- | 9106e19b56c1: Pull complete | + | " |
- | ee2f70ac7c7d: Pull complete | + | " |
- | 7257ad6985e8: Pull complete | + | " |
- | 18f5c2055da2: Pull complete | + | " |
- | 85293a6fdd80: Pull complete | + | " |
- | 9e797eeb0c14: Pull complete | + | " |
- | f16178842884: Pull complete | + | " |
- | 13899c06d3f8: Pull complete | + | " |
- | 70c27fe4c3c5: Pull complete | + | " |
- | d32c8ad2d9d7: Pull complete | + | " |
- | 07fe445494e6: Pull complete | + | root@debian9:~/mongodb# |
- | 63b8de7b32fe: Pull complete | + | root@debian9:~/mongodb# mongo --host 172.17.0.4 |
- | e4b721952e22: Pull complete | + | MongoDB shell version v4.0.8 |
- | d9ede6dd6f74: Pull complete | + | connecting to: mongodb:// |
- | 0af4f74bfd92: Pull complete | + | Implicit session: session { " |
- | e4e7c47b969f: Pull complete | + | MongoDB server version: 4.1.9 |
- | 69aff47f3112: Pull complete | + | WARNING: shell and server versions do not match |
- | Digest: sha256:201d004f55669dd2c0884f00fc44145fb0da8cafa465bf22cbaacecaf81138d4 | + | Server has startup warnings: |
- | Status: Downloaded newer image for wordpress:latest | + | 2019-04-09T17:50: |
- | 9eb2f7fbfbd25307ed2f463c7eb3bef40bfa556174e68750bb76b8d032546129 | + | 2019-04-09T17:50: |
+ | 2019-04-09T17:50: | ||
+ | 2019-04-09T17:50: | ||
+ | 2019-04-09T17:50: | ||
+ | 2019-04-09T17:50:13.459+0000 I CONTROL | ||
+ | 2019-04-09T17:50: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17:50: | ||
+ | 2019-04-09T17: | ||
+ | --- | ||
+ | Enable MongoDB' | ||
+ | metrics about your deployment (disk utilization, | ||
+ | |||
+ | The monitoring data will be available on a MongoDB website with a unique URL accessible to you | ||
+ | and anyone you share the URL with. MongoDB may use this information to make product | ||
+ | improvements and to suggest MongoDB products and deployment options to you. | ||
+ | |||
+ | To enable free monitoring, run the following command: db.enableFreeMonitoring() | ||
+ | To permanently disable this reminder, run the following command: db.disableFreeMonitoring() | ||
+ | --- | ||
+ | |||
+ | > exit | ||
+ | bye | ||
+ | root@debian9: | ||
</ | </ | ||
- | Vérifiez | + | Notez que lors de la compilation de l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER ID | + | REPOSITORY |
- | 9eb2f7fbfbd2 | + | i2tch/ |
- | 67831dacf002 | + | < |
+ | <none> < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/mongodb | ||
+ | < | ||
+ | < | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Vérifiez que le Wordpress fonctionne | + | =====LAB #2 - Créer un Dockerfile===== |
+ | |||
+ | ====2.1 - Création et test du script==== | ||
+ | |||
+ | Créez un répertoire nommé myDocker | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [1]WordPress | + | root@debian9:~/mongodb# cd ~/myDocker |
- | Select a default language [English (United States)________] | + | root@debian9: |
+ | </ | ||
- | | + | Créez le fichier myEntrypoint.sh : |
- | References | + | < |
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | # | ||
+ | if [ -z " | ||
+ | echo "La variable myVariable doit être renseignée" | ||
+ | return 1 | ||
+ | fi | ||
- | 1. https:// | + | while true; |
+ | do | ||
+ | echo $1 \($(date +%H:%M:%S)\); | ||
+ | sleep " | ||
+ | done | ||
+ | </code> | ||
- | root@debian9:~/ | + | Testez ce script |
- | " | + | |
- | " | + | |
- | " | + | |
- | + | ||
- | root@debian9: | + | |
- | | + | |
- | | + | |
- | | + | < |
+ | root@debian9: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | ^C | ||
+ | root@debian9: | ||
+ | </ | ||
- | References | + | Rendez ce script exécutable : |
- | 1. https://wordpress.org/ | + | < |
+ | root@debian9:~/myDocker# chmod u+x myEntrypoint.sh | ||
</ | </ | ||
- | ====Gestion d'une Architecture de Microservices==== | + | Créez maintenant le fichier **Dockerfile** dans le répertoire **~/ |
- | Vous allez mettre en place une application simple sous forme de microservices, | + | < |
+ | root@debian9:~/myDocker# vi Dockerfile | ||
+ | root@debian9: | ||
+ | FROM centos: | ||
+ | MAINTAINER i2tch " | ||
+ | COPY myEntrypoint.sh / | ||
+ | ENV myVariable 3 | ||
+ | ENTRYPOINT ["/ | ||
+ | CMD [" | ||
+ | </ | ||
- | {{ :elearning: | + | Générez maintenant l' |
- | 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: | ||
+ | Sending build context to Docker daemon | ||
+ | Step 1/6 : FROM centos: | ||
+ | | ||
+ | Step 2/6 : MAINTAINER i2tch " | ||
+ | | ||
+ | Removing intermediate container 02c700ed04da | ||
+ | | ||
+ | Step 3/6 : COPY myEntrypoint.sh / | ||
+ | | ||
+ | Step 4/6 : ENV myVariable 3 | ||
+ | | ||
+ | Removing intermediate container 3288bf6291ad | ||
+ | | ||
+ | Step 5/6 : ENTRYPOINT ["/ | ||
+ | | ||
+ | Removing intermediate container 8dcba2c41520 | ||
+ | | ||
+ | Step 6/6 : CMD [" | ||
+ | | ||
+ | Removing intermediate container f891fbcfaad0 | ||
+ | | ||
+ | Successfully built 7925ba23abb2 | ||
+ | Successfully tagged i2tch/ | ||
+ | </ | ||
- | {{ :elearning: | + | Lancez le conteneur |
- | 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. | + | < |
+ | root@debian9: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | ^Cmycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | ^P^Q | ||
+ | root@debian9: | ||
+ | </ | ||
- | L' | + | Constatez que le conteneur est toujours en cours de fonctionnement |
- | {{ :elearning:workbooks:debian:6:avance:kubernetes16.png? | + | < |
+ | root@debian9:~/myDocker# docker ps | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | root@debian9:~/ | ||
+ | root@debian9:~/myDocker# docker logs myDocker | tail | ||
+ | mycommand (18:08:25) | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | </ | ||
- | Cette application peut être mise en place sous docker avec les commandes suivantes | + | Arrêtez le conteneur |
< | < | ||
- | docker | + | root@debian9: |
- | docker run -d --name=db postgres: | + | myDocker |
- | docker run -d --name=vote -p 5000:80 --link redis:redis dockersamples/examplevotingapp_vote | + | root@debian9:~/myDocker# docker ps |
- | docker | + | CONTAINER ID IMAGE |
- | docker run -d --name=worker --link db:db --link redis:redis dockersamples/examplevotingapp_worker | + | b3380889eb75 |
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
</ | </ | ||
- | 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' | + | Démarrez |
+ | < | ||
+ | root@debian9: | ||
+ | myDocker | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | </ | ||
- | =====LAB #8 - Superviser les Conteneurs===== | + | Mettez le conteneur en pause : |
- | ====Les Journaux==== | + | < |
+ | root@debian9: | ||
+ | myDocker | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | </ | ||
- | Consultez les logs d'un conteneur | + | Supprimez la pause : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@332aa9930f30:/# | + | myDocker |
- | bash: ip: command not found | + | root@debian9:~/myDocker# docker ps |
- | root@332aa9930f30:/# ip address | + | CONTAINER ID IMAGE |
- | bash: ip: command not found | + | 140ecfdd80b7 |
- | root@332aa9930f30: | + | b3380889eb75 |
- | bash: ifconfig: command not found | + | d2ddb4f8ca8a |
- | root@332aa9930f30: | + | c080793965de |
- | bin boot core data dev | + | |
- | root@332aa9930f30: | + | |
- | root@332aa9930f30: | + | |
- | root@332aa9930f30:/# docker run -itd --name centos3 --link centos2: | + | |
- | bash: docker: command not found | + | |
- | root@332aa9930f30: | + | |
- | exit | + | |
</ | </ | ||
- | ====Les Processus==== | + | Lancez maintenant le conteneur avec un paramètre : |
- | Consultez les processus | + | < |
+ | 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: | ||
+ | </ | ||
+ | |||
+ | Changez la valeur de la variable | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | UID | + | myDocker |
- | root | + | root@debian9:~/myDocker# docker run -d --name myDocker --env myVariable=1 i2tch/ |
+ | fbbe3b48c63310e37a3bad5fc962361c39c045a107f47980614efd6b2e8d3981 | ||
+ | root@debian9:~/myDocker# docker logs myDocker | ||
+ | mycommand (18:14:47) | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | root@debian9: | ||
</ | </ | ||
- | ====L' | + | ====2.2 - Bonnes Pratiques liées au Cache==== |
- | Pour voir l' | + | ===Opérations Non-Idempotentes=== |
+ | |||
+ | Créez | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER | + | root@debian9: |
- | centos3 | + | root@debian9: |
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | FROM ubuntu: | ||
+ | RUN date +%N > /tmp/moment | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/tmp/moment" | ||
</ | </ | ||
- | =====LAB #9 - Gestion des Ressources===== | + | Le fichier Dokerfile contient une opération non idempotente. |
- | La gestion de base des ressources allouées à un conteneur peut être réalisée par l' | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | * --memory | + | Compilez l' |
- | * --cpu-shares | + | |
- | ====Limiter la Mémoire==== | + | < |
+ | 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: | ||
+ | </ | ||
- | Par exemple, exécutez | + | Exécuter maintenant |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | fc8ce16b3ec86433662719ca1f710a0588951d4f4abb8d90159b5953f419eef7 | + | 369009216 |
</ | </ | ||
- | Exécutez ensuite | + | Supprimez maintenant le conteneur et relancez |
< | < | ||
- | CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS | + | root@debian9: |
- | fc8ce16b3ec8 | + | test1 |
+ | root@debian9: | ||
+ | Sending build context to Docker daemon | ||
+ | Step 1/4 : FROM ubuntu: | ||
+ | | ||
+ | Step 2/4 : RUN date +%N > /tmp/ | ||
+ | | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT [" | ||
+ | | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | | ||
+ | Successfully built c55a42a18572 | ||
+ | Successfully tagged testcache: | ||
+ | root@debian9: | ||
+ | </ | ||
+ | |||
+ | Lancez un conteneur à partir de l' | ||
+ | |||
+ | < | ||
+ | root@debian9: | ||
+ | 369009216 | ||
</ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ----- | + | Pour contourner ce problème, il est possible d' |
- | =====ChangeLog===== | + | < |
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | FROM ubuntu: | ||
+ | RUN date +%N > /tmp/moment \ | ||
+ | && echo " | ||
+ | ENTRYPOINT [" | ||
+ | CMD ["/ | ||
+ | </ | ||
- | ====2020.01==== | + | Supprimez maintenant le conteneur et relancez la compilation de l' |
- | Première version de 2020. | + | < |
+ | root@debian9: | ||
+ | test1 | ||
+ | root@debian9: | ||
+ | Sending build context to Docker daemon | ||
+ | Step 1/4 : FROM ubuntu: | ||
+ | | ||
+ | Step 2/4 : RUN date +%N > / | ||
+ | | ||
+ | Removing intermediate container 3d2a5cee6ac8 | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT [" | ||
+ | | ||
+ | Removing intermediate container 88c0cec68659 | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | Removing intermediate container 82d2162bb701 | ||
+ | | ||
+ | Successfully built a54c4af89994 | ||
+ | Successfully tagged testcache: | ||
+ | </ | ||
- | ====2020.02==== | + | Lancez un conteneur à partir de l' |
- | * **Fixed** - Dead Link : **https://docs.docker.com/engine/ | + | < |
+ | root@debian9:~/bestp# | ||
+ | 746997174 | ||
+ | </code> | ||
- | * **Fixed** - Erreur : **docker run -it --name mongo2 --net none i2tch/ | ||
- | | ||
----- | ----- | ||
- | < | + | |
- | <div align=" | + | Copyright © 2022 Hugh Norris. |
- | Copyright © 2020 Hugh NORRIS | + | |
- | </ | + | |
- | </ | + |