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/06/26 11:52] – 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 |
- | * LAB #8 - Superviser les Conteneurs | + | * 1.7 - ENTRYPOINT |
- | * Les Journaux | + | * 1.8 - EXPOSE |
- | * Les Processus | + | * 1.9 - CMD |
- | * L' | + | * 1.10 - Autres Commandes |
- | * LAB #9 - Gestion des Ressources | + | * LAB #2 - Créer un Dockerfile |
+ | * 2.1 - Création et test du script | ||
+ | * 2.2 - Bonnes Pratiques liées au Cache | ||
- | =====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:// |
- | root@debian9:~# docker | + | ENV GOSU_VERSION 1.11 |
+ | # grab " | ||
+ | ENV JSYAML_VERSION 3.13.0 | ||
+ | |||
+ | RUN set -ex; \ | ||
+ | \ | ||
+ | apt-get update; \ | ||
+ | apt-get install -y --no-install-recommends \ | ||
+ | wget \ | ||
+ | ; \ | ||
+ | if ! command -v gpg > /dev/null; then \ | ||
+ | apt-get install -y --no-install-recommends gnupg dirmngr; \ | ||
+ | fi; \ | ||
+ | rm -rf / | ||
+ | \ | ||
+ | dpkgArch=" | ||
+ | wget -O / | ||
+ | wget -O / | ||
+ | export GNUPGHOME=" | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; | ||
+ | # gpg --batch --verify / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | chmod +x / | ||
+ | gosu --version; \ | ||
+ | gosu nobody true; \ | ||
+ | \ | ||
+ | wget -O /js-yaml.js " | ||
+ | # TODO some sort of download verification here | ||
+ | \ | ||
+ | apt-get purge -y --auto-remove wget | ||
+ | |||
+ | RUN mkdir / | ||
+ | |||
+ | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B | ||
+ | RUN set -ex; \ | ||
+ | export GNUPGHOME=" | ||
+ | for key in $GPG_KEYS; do \ | ||
+ | gpg --batch --keyserver pgp.mit.edu --recv-keys " | ||
+ | done; \ | ||
+ | gpg --batch --export $GPG_KEYS > / | ||
+ | command -v gpgconf && gpgconf --kill all || :; \ | ||
+ | rm -r " | ||
+ | apt-key list | ||
+ | |||
+ | # Allow build-time overrides (eg. to build image with MongoDB Enterprise version) | ||
+ | # Options for MONGO_PACKAGE: | ||
+ | # Options for MONGO_REPO: repo.mongodb.org OR repo.mongodb.com | ||
+ | # Example: docker build --build-arg MONGO_PACKAGE=mongodb-enterprise --build-arg MONGO_REPO=repo.mongodb.com . | ||
+ | ARG MONGO_PACKAGE=mongodb-org-unstable | ||
+ | ARG MONGO_REPO=repo.mongodb.org | ||
+ | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} | ||
+ | |||
+ | ENV MONGO_MAJOR 4.1 | ||
+ | ENV MONGO_VERSION 4.1.9 | ||
+ | # bashbrew-architectures: | ||
+ | RUN echo "deb http:// | ||
+ | |||
+ | RUN set -x \ | ||
+ | && apt-get update \ | ||
+ | && apt-get install -y \ | ||
+ | ${MONGO_PACKAGE}=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ | ||
+ | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ | ||
+ | && rm -rf / | ||
+ | && rm -rf / | ||
+ | && mv / | ||
+ | |||
+ | RUN mkdir -p /data/db / | ||
+ | && chown -R mongodb: | ||
+ | VOLUME /data/db / | ||
+ | |||
+ | COPY docker-entrypoint.sh / | ||
+ | ENTRYPOINT [" | ||
+ | |||
+ | EXPOSE 27017 | ||
+ | CMD [" | ||
+ | </file> | ||
+ | |||
+ | Le fichier docker-entrypoint.sh sert à lancer le serveur mongodb dans le conteneur : | ||
+ | |||
+ | <file txt docker-entrypoint.sh> | ||
+ | # | ||
+ | set -Eeuo pipefail | ||
+ | |||
+ | if [ " | ||
+ | set -- mongod " | ||
+ | fi | ||
+ | |||
+ | originalArgOne=" | ||
+ | |||
+ | # allow the container to be started with `--user` | ||
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
+ | |||
+ | # make sure we can write to stdout and stderr as " | ||
+ | # (for our " | ||
+ | chown --dereference mongodb "/ | ||
+ | # ignore errors thanks to https:// | ||
+ | |||
+ | exec gosu mongodb " | ||
+ | fi | ||
+ | |||
+ | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | ||
+ | # https:// | ||
+ | if [[ " | ||
+ | numa=' | ||
+ | if $numa true &> /dev/null; then | ||
+ | set -- $numa "$@" | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # usage: file_env VAR [DEFAULT] | ||
+ | # ie: file_env ' | ||
+ | # (will allow for " | ||
+ | # " | ||
+ | file_env() { | ||
+ | local var=" | ||
+ | local fileVar=" | ||
+ | local def=" | ||
+ | if [ " | ||
+ | echo >&2 " | ||
+ | exit 1 | ||
+ | fi | ||
+ | local val=" | ||
+ | if [ " | ||
+ | val=" | ||
+ | elif [ " | ||
+ | val=" | ||
+ | fi | ||
+ | export " | ||
+ | unset " | ||
+ | } | ||
+ | |||
+ | # see https:// | ||
+ | _mongod_hack_have_arg() { | ||
+ | local checkArg=" | ||
+ | local arg | ||
+ | for arg; do | ||
+ | case " | ||
+ | " | ||
+ | return 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | return 1 | ||
+ | } | ||
+ | # _mongod_hack_get_arg_val ' | ||
+ | _mongod_hack_get_arg_val() { | ||
+ | local checkArg=" | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | case " | ||
+ | " | ||
+ | echo " | ||
+ | return 0 | ||
+ | ;; | ||
+ | " | ||
+ | echo " | ||
+ | return 0 | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | return 1 | ||
+ | } | ||
+ | declare -a mongodHackedArgs | ||
+ | # _mongod_hack_ensure_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_arg() { | ||
+ | local ensureArg=" | ||
+ | mongodHackedArgs=( " | ||
+ | if ! _mongod_hack_have_arg " | ||
+ | mongodHackedArgs+=( " | ||
+ | fi | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_no_arg() { | ||
+ | local ensureNoArg=" | ||
+ | mongodHackedArgs=() | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | if [ " | ||
+ | continue | ||
+ | fi | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_no_arg ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_no_arg_val() { | ||
+ | local ensureNoArg=" | ||
+ | mongodHackedArgs=() | ||
+ | while [ " | ||
+ | local arg=" | ||
+ | case " | ||
+ | " | ||
+ | shift # also skip the value | ||
+ | continue | ||
+ | ;; | ||
+ | " | ||
+ | # value is already included | ||
+ | continue | ||
+ | ;; | ||
+ | esac | ||
+ | mongodHackedArgs+=( " | ||
+ | done | ||
+ | } | ||
+ | # _mongod_hack_ensure_arg_val ' | ||
+ | # set -- " | ||
+ | _mongod_hack_ensure_arg_val() { | ||
+ | local ensureArg=" | ||
+ | local ensureVal=" | ||
+ | _mongod_hack_ensure_no_arg_val " | ||
+ | mongodHackedArgs+=( " | ||
+ | } | ||
+ | |||
+ | # _js_escape 'some " | ||
+ | _js_escape() { | ||
+ | jq --null-input --arg ' | ||
+ | } | ||
+ | |||
+ | jsonConfigFile=" | ||
+ | tempConfigFile=" | ||
+ | _parse_config() { | ||
+ | if [ -s " | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | local configPath | ||
+ | if configPath=" | ||
+ | # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) | ||
+ | # see https:// | ||
+ | mongo --norc --nodb --quiet --eval " | ||
+ | jq ' | ||
+ | return 0 | ||
+ | fi | ||
+ | |||
+ | return 1 | ||
+ | } | ||
+ | dbPath= | ||
+ | _dbPath() { | ||
+ | if [ -n " | ||
+ | echo " | ||
+ | return | ||
+ | fi | ||
+ | |||
+ | if ! dbPath=" | ||
+ | if _parse_config " | ||
+ | dbPath=" | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | if _mongod_hack_have_arg --configsvr " | ||
+ | _parse_config " | ||
+ | && | ||
+ | && | ||
+ | }; then | ||
+ | # if running as config server, then the default dbpath is / | ||
+ | # https:// | ||
+ | dbPath=/ | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | : " | ||
+ | |||
+ | echo " | ||
+ | } | ||
+ | |||
+ | if [ " | ||
+ | file_env ' | ||
+ | file_env ' | ||
+ | # pre-check a few factors to see if it's even worth bothering with initdb | ||
+ | shouldPerformInitdb= | ||
+ | if [ " | ||
+ | # if we have a username/ | ||
+ | _mongod_hack_ensure_arg ' | ||
+ | set -- " | ||
+ | shouldPerformInitdb=' | ||
+ | elif [ " | ||
+ | cat >&2 << | ||
+ | error: missing ' | ||
+ | both must be specified for a user to be created | ||
+ | EOF | ||
+ | exit 1 | ||
+ | fi | ||
+ | |||
+ | if [ -z " | ||
+ | # if we've got any / | ||
+ | for f in / | ||
+ | case " | ||
+ | *.sh|*.js) # this should match the set of files we check for below | ||
+ | shouldPerformInitdb=" | ||
+ | break | ||
+ | ;; | ||
+ | esac | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | # check for a few known paths (to determine whether we've already initialized and should thus skip our initdb scripts) | ||
+ | if [ -n " | ||
+ | dbPath=" | ||
+ | for path in \ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ; do | ||
+ | if [ -e " | ||
+ | shouldPerformInitdb= | ||
+ | break | ||
+ | fi | ||
+ | done | ||
+ | fi | ||
+ | |||
+ | if [ -n " | ||
+ | mongodHackedArgs=( " | ||
+ | if _parse_config " | ||
+ | _mongod_hack_ensure_arg_val --config " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg_val --bind_ip 127.0.0.1 " | ||
+ | _mongod_hack_ensure_arg_val --port 27017 " | ||
+ | _mongod_hack_ensure_no_arg --bind_ip_all " | ||
+ | |||
+ | # remove " | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_no_arg --auth " | ||
+ | if [ " | ||
+ | _mongod_hack_ensure_no_arg_val --replSet " | ||
+ | fi | ||
+ | |||
+ | sslMode=" | ||
+ | _mongod_hack_ensure_arg_val --sslMode " | ||
+ | |||
+ | if stat "/ | ||
+ | # https:// | ||
+ | # https:// | ||
+ | _mongod_hack_ensure_arg_val --logpath "/ | ||
+ | else | ||
+ | initdbLogPath=" | ||
+ | echo >&2 " | ||
+ | _mongod_hack_ensure_arg_val --logpath " | ||
+ | fi | ||
+ | _mongod_hack_ensure_arg --logappend " | ||
+ | |||
+ | pidfile=" | ||
+ | rm -f " | ||
+ | _mongod_hack_ensure_arg_val --pidfilepath " | ||
+ | |||
+ | " | ||
+ | |||
+ | mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) | ||
+ | |||
+ | # check to see that our " | ||
+ | # https:// | ||
+ | tries=30 | ||
+ | while true; do | ||
+ | if ! { [ -s " | ||
+ | # bail ASAP if " | ||
+ | echo >& | ||
+ | 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 / | ||
+ | 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/* |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
... | ... | ||
- | | + | RUN set -ex; \ |
- | "/data/configdb": | + | \ |
- | "/data/db": {} | + | 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="$(dpkg --print-architecture | awk -F- '{ print $NF }' | ||
+ | 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 / | ||
... | ... | ||
- | </ | ||
- | En regardant le contenu du répertoire **/data/db**, on constate une arborescence classique de stockage de données de mongodb : | + | 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 > /etc/ | ||
+ | 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 /data/configdb \ |
- | root@debian9: | + | && chown -R mongodb: |
- | journal | + | ... |
- | </code> | + | </file> |
- | Arrêtez et supprimez le conteneur | + | Cette commande lance un processus dans la construction de l' |
- | < | + | Il existe un autre syntaxe de la commande RUN appelé le format exec, à savoir |
- | root@debian9:~# docker stop mongo2 | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | b9773e4aa06d | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | </ | + | |
- | Re-créez maintenant un conteneur à partir de l' | + | RUN ["/bin/ |
- | <code> | + | <WRAP center round important> |
- | root@debian9:~# docker run -d --name mongo2 i2tch/ | + | **Important** |
- | a8382642c4e849337e12a60419b10f63ea21251dfcc2c6050284ca3eed7fa13d | + | </WRAP> |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | a8382642c4e8 | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | </code> | + | |
- | Utilisez de nouveau la commande **docker inspect** pour identifier le point de montage du répertoire **/ | + | ====1.4 - ENV==== |
- | <code> | + | Cette commande permet de fixer la valeur d'une variable d' |
- | root@debian9: | + | |
+ | <file> | ||
... | ... | ||
- | " | + | ENV GOSU_VERSION 1.11 |
- | { | + | # grab "js-yaml" |
- | "Type": | + | ENV JSYAML_VERSION 3.13.0 |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
... | ... | ||
- | </ | ||
- | <WRAP center round important> | + | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B |
- | **Important** : Notez que le répertoire des données du précédent conteneur, **/ | + | ... |
- | </ | + | |
- | Les conteneurs n' | + | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} |
- | <code> | + | ENV MONGO_MAJOR 4.1 |
- | root@debian9: | + | ENV MONGO_VERSION 4.1.95 |
- | total 52 | + | ... |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 3bf724ceb38ce0792469d7e403f05b6794f27e0aa72bda51a8ab75b2df5ae87c | + | </file> |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 46d11d005d05757609ff76159ce0992d210089c5247fa54b024706a20b0de501 | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:43 76dcc0ccbe6604278cf8e8da0398a807f5d0719087f17c227c8504be24456d43 | + | **et** dans les conteneurs générés à partir de l'image construite. |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 9c84c2d1a0db811a3c13dce354ba21169f3073513c8d025dd96c5f902364d44a | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 02:33 a6177cf4b46089356280f084dd2e272f673aa4a81accb53f031267fafcee6050 | + | ====1.5 - VOLUME==== |
- | drwxr-xr-x 3 root root 4096 Sep 6 16:07 cc38fa97138adc55976aa16993d8920c5f7da922ad1b2a07936d30cc82d59f38 | + | |
- | -rw------- 1 root root 32768 Sep 7 09:43 metadata.db | + | < |
- | </code> | + | ... |
+ | VOLUME | ||
+ | ... | ||
+ | </file> | ||
+ | |||
+ | Cette commande expose les répertoires passés en argument afin qu'ils puissent être mappés vers des répertoires sur la machine hôte ou ailleurs, tel que nous avons vu avec l' | ||
+ | |||
+ | ====1.6 | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | COPY docker-entrypoint.sh / | ||
+ | ... | ||
+ | </file> | ||
+ | |||
+ | Cette commande permet de récupérer les fichiers dans le contexte et de les copier dans l' | ||
+ | |||
+ | **Attention** : tous les fichiers dans le contexte sont inclus dans l' | ||
+ | |||
+ | Il est possible d' | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** : Notez que non-seulement ceci représente une source | + | **Important** |
</ | </ | ||
- | ====Gestion Manuelle d'un Volume==== | + | ====1.7 - ENTRYPOINT==== |
- | 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 : | + | < |
+ | ... | ||
+ | ENTRYPOINT [" | ||
+ | ... | ||
+ | </file> | ||
- | < | + | Cette commande stipule la commande qui sera exécutée lors du démarrage du conteneur. |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | 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: | + | |
- | 2017-09-07T08: | + | |
- | 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 **/ | + | Deux cas de figure se présentent |
- | < | + | * ENTRYPOINT suivi d'une chaîne |
- | root@debian9: | + | |
- | total 68 | + | |
- | 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:46 511e23f818d5cf60f4333a3fe8fd2e4333c900dec6eee97f70448bfb0091184d | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:53 5ca72be4140ecf1271efe7342cf7cd58ce66fc3673d12c04b8503603b8cee66c | + | |
- | 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 65536 Sep 7 09:53 metadata.db | + | |
- | drwxr-xr-x 3 root root 4096 Sep 7 09:46 persistent_data | + | |
- | </ | + | |
- | Arrêtez et supprimez | + | Dans le fichier |
- | <code> | + | <file> |
- | root@debian9: | + | ... |
- | mongo2 | + | originalArgOne="$1" |
- | root@debian9: | + | |
- | mongo2 | + | |
- | root@debian9: | + | |
- | ad672c3038245c25a36162d05820c21f7250557ac342582d0908d3ca33799e37 | + | |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | ad672c303824 | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | </ | + | |
- | Encore une fois, cherchez le point de montage de **/data/db** grâce à l'utilisation de la commande **docker inspect** : | + | # allow the container to be started with `--user` |
+ | # all mongo* commands should be dropped to the correct user | ||
+ | if [[ " | ||
+ | if [ " | ||
+ | find / | ||
+ | fi | ||
- | <code> | + | # make sure we can write to stdout and stderr as " |
- | root@debian9:~# docker | + | # (for our " |
+ | chown --dereference mongodb "/ | ||
+ | # ignore errors thanks to https:// | ||
+ | |||
+ | exec gosu mongodb " | ||
+ | fi | ||
+ | |||
+ | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | ||
+ | # https:// | ||
+ | if [[ " | ||
+ | numa=' | ||
+ | if $numa true &> /dev/null; then | ||
+ | set -- $numa " | ||
+ | fi | ||
+ | fi | ||
... | ... | ||
- | | + | exec "$@" |
- | { | + | </ |
- | " | + | |
- | " | + | si la valeur du paramètre passé à entrypoint.sh est **mongod**, le script affecte l' |
- | " | + | |
- | " | + | Ce fichier finit par "$@" |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | "Mode": "z", | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ... | + | |
- | </ | + | |
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | https:// | + | ====1.8 - EXPOSE==== |
- | =====LAB #6 - Gestion du Réseau===== | + | < |
+ | ... | ||
+ | EXPOSE 27017 | ||
+ | ... | ||
+ | </ | ||
- | Docker fournit trois réseaux | + | Cette commande permet d' |
+ | |||
+ | ====1.9 - CMD==== | ||
+ | |||
+ | < | ||
+ | ... | ||
+ | CMD [" | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | Ceci représente la valeur du paramètre | ||
+ | |||
+ | ====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: | + | root@debian9: |
- | NETWORK ID NAME DRIVER | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | 6bda460c97c6 | + | |
</ | </ | ||
- | ====Bridge==== | + | Consultez la liste de images : |
- | Ce type de réseau est limité aux conteneurs d'un hôte unique exécutant Docker. Les conteneurs ne peuvent communiquer qu' | + | < |
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | < | ||
+ | i2tch/ | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </ | ||
- | Par défaut Docker fonctionne en mode **Pont** ou (// | + | Notez que l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 3: docker0: < | + | root@debian9:~/mongodb# docker images |
- | link/ether 02: | + | REPOSITORY |
- | inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 | + | i2tch/ |
- | valid_lft forever preferred_lft forever | + | i2tch/mongodb |
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Démarrez un conteneur | + | Démarrez un conteneur à partir |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 2169360fcbfdbd6e68ea969a95edeb6fc42603c23ee42f03ceec286276519855 | + | 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 | ||
</ | </ | ||
- | Lancez ensuite la commande | + | <WRAP center round important> |
+ | **Important** - Notez que le fichier docker-entrypoint.sh n' | ||
+ | </ | ||
+ | |||
+ | Recompilez donc l' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [ | + | mongo1 |
- | { | + | root@debian9:~/mongodb# chmod +x docker-entrypoint.sh |
- | " | + | root@debian9:~/mongodb# docker build . |
- | " | + | Sending build context to Docker daemon |
- | " | + | Step 1/22 : FROM ubuntu:bionic |
- | " | + | ---> 94e814e2efa8 |
- | " | + | Step 2/22 : RUN groupadd -r mongodb && useradd -r -g mongodb mongodb |
- | " | + | ---> Using cache |
- | " | + | ---> f40ac453fa97 |
- | " | + | 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 |
- | " | + | ---> adc57da1b19f |
- | { | + | Step 4/22 : ENV GOSU_VERSION 1.11 |
- | " | + | ---> Using cache |
- | " | + | |
- | } | + | Step 5/22 : ENV JSYAML_VERSION 3.13.0 |
- | ] | + | ---> Using cache |
- | }, | + | ---> 3bf216d921d6 |
- | " | + | ... |
- | " | + | Removing intermediate container a98ae692fe1f |
- | " | + | ---> 04c2e98927c3 |
- | " | + | Step 17/22 : RUN mkdir -p /data/db / |
- | " | + | ---> Running in d0f5bee34571 |
- | }, | + | Removing intermediate container d0f5bee34571 |
- | " | + | ---> d5b95e9e63e1 |
- | " | + | Step 18/22 : VOLUME /data/db / |
- | " | + | ---> Running in c7626528a9b9 |
- | " | + | Removing intermediate container c7626528a9b9 |
- | " | + | ---> 4250613adf6a |
- | " | + | Step 19/22 : COPY docker-entrypoint.sh / |
- | " | + | ---> eedfd53da0f8 |
- | " | + | Step 20/22 : ENTRYPOINT ["docker-entrypoint.sh"] |
- | }, | + | ---> Running in eff53d0213d1 |
- | " | + | Removing intermediate container eff53d0213d1 |
- | " | + | ---> 716abf2faa87 |
- | " | + | Step 21/22 : EXPOSE 27017 |
- | " | + | ---> Running in 5139fcf19d7f |
- | " | + | Removing intermediate container 5139fcf19d7f |
- | " | + | ---> fc5896e08fd6 |
- | } | + | Step 22/22 : CMD ["mongod"] |
- | }, | + | ---> Running in 458d6f15cdf2 |
- | " | + | Removing intermediate container 458d6f15cdf2 |
- | " | + | ---> 12e00099ca8d |
- | " | + | Successfully built 12e00099ca8d |
- | " | + | root@debian9:~/ |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
</ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | Vous pouvez déconnecter un conteneur du réseau en utilisant | + | Consultez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | REPOSITORY |
- | [ | + | < |
- | { | + | i2tch/ |
- | | + | i2tch/ |
- | | + | nginx |
- | | + | centos |
- | | + | ubuntu |
- | | + | ubuntu |
- | | + | hello-world |
- | | + | root@debian9:~/mongodb# docker tag 12e0 i2tch/ |
- | " | + | root@debian9:~/mongodb# docker images |
- | " | + | REPOSITORY |
- | " | + | i2tch/ |
- | { | + | i2tch/ |
- | " | + | i2tch/ |
- | " | + | nginx |
- | } | + | centos |
- | ] | + | ubuntu |
- | | + | ubuntu |
- | " | + | hello-world |
- | " | + | |
- | " | + | |
- | " | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | | + | |
- | | + | |
- | "com.docker.network.bridge.default_bridge": | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
</ | </ | ||
- | Créez maintenant votre propre réseau ponté appelé **my-bridged-network** | + | Lancez un conteneur à partir de la dernière image : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | ceb7ba7493933c55d181bc92b1f799ca07bfe84b168d52a6ac648c1a906093f3 | + | e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a |
- | root@debian9: | + | |
- | NETWORK ID NAME | + | |
- | 495b3db75b0d | + | |
- | e1ed4de2f947 | + | |
- | ceb7ba749393 | + | |
- | 6bda460c97c6 | + | |
</ | </ | ||
- | Bien évidement, ce réseau | + | Utilisez la commande **docker ps** pour visualiser si le processus mongodb |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [ | + | CONTAINER ID IMAGE |
- | { | + | e91a055283f4 |
- | | + | d2ddb4f8ca8a |
- | "Id": " | + | c080793965de |
- | " | + | |
- | "Scope": " | + | |
- | "Driver": " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
</ | </ | ||
- | Lancez maintenant deux conteneurs et consultez les informations concernant le réseau | + | Connectez-vous à mongodb à partir de votre machine hôte : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 9f36a628c72b383edfd4dc13ee4e4b2eaf5be0078d780f0334fcb8be0d977d0e | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | 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 |
- | aaed3bc8e404ee1bccd6c87b39de32332940b5391514691fc70188edb17c1d7c | + | 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 inspect --format=' | + | To enable free monitoring, run the following command: db.enableFreeMonitoring() |
- | {" | + | To permanently disable this reminder, run the following command: db.disableFreeMonitoring() |
+ | --- | ||
- | root@debian9: | + | > exit |
- | {" | + | bye |
+ | root@debian9: | ||
+ | </ | ||
- | root@debian9: | + | Notez que lors de la compilation de l'image finale, une image a été créée lors de chaque instruction dans le fichier Dockerfile sauf en cas d'utilisation d'une image en cache : |
- | 172.17.0.3 | + | |
- | root@debian9: | + | < |
- | 172.17.0.4 | + | root@debian9: |
+ | REPOSITORY | ||
+ | i2tch/ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/ | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | i2tch/ | ||
+ | < | ||
+ | < | ||
+ | nginx | ||
+ | centos | ||
+ | ubuntu | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Mettez le conteneur **centos1** dans le réseau **my-bridged-network** : | + | =====LAB #2 - Créer un Dockerfile===== |
- | < | + | ====2.1 |
- | root@debian9: | + | |
- | root@debian9:~# docker network inspect my-bridged-network | + | Créez un répertoire nommé myDocker |
- | [ | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | root@debian9: | + | < |
- | 172.17.0.3172.25.0.2 | + | root@debian9: |
+ | root@debian9: | ||
+ | root@debian9: | ||
</ | </ | ||
- | <WRAP center round important> | + | Créez |
- | **Important** : Notez que le conteneur **centos1** se trouve dans deux réseaux. | + | |
- | </ | + | |
- | + | ||
- | Faites la même chose pour le conteneur **centos2** | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | root@debian9: | ||
+ | # | ||
+ | if [ -z " | ||
+ | echo "La variable myVariable doit être renseignée" | ||
+ | return 1 | ||
+ | fi | ||
- | root@debian9: | + | while true; |
- | [ | + | do |
- | { | + | echo $1 \($(date |
- | " | + | sleep "$myVariable"; |
- | " | + | done |
- | " | + | |
- | " | + | |
- | "Driver": " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | { | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | }, | + | |
- | " | + | |
- | " | + | |
- | } | + | |
- | ] | + | |
- | + | ||
- | root@debian9: | + | |
- | 172.17.0.4172.25.0.3 | + | |
</ | </ | ||
- | Connectez-vous au conteneur **centos1** en lançant bash : | + | Testez ce script |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | salut (20: | ||
+ | ^C | ||
+ | root@debian9: | ||
</ | </ | ||
- | Vérifiez que la connectivité fonctionne | + | Rendez ce script exécutable |
< | < | ||
- | [root@9f36a628c72b | + | root@debian9:~/myDocker# chmod u+x myEntrypoint.sh |
- | 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. | + | Créez maintenant le fichier **Dockerfile** dans le répertoire **~/ |
- | + | ||
- | Il est possible d' | + | |
< | < | ||
- | [root@9f36a628c72b /]# exit | + | root@debian9: |
- | exit | + | root@debian9: |
- | root@debian9: | + | FROM centos: |
- | mongo2 | + | MAINTAINER i2tch "infos@i2tch.eu" |
- | root@debian9: | + | COPY myEntrypoint.sh /entrypoint.sh |
- | mongo2 | + | ENV myVariable 3 |
- | root@debian9:~# docker run -it --name mongo2 --dns 8.8.8.8 i2tch/ | + | ENTRYPOINT ["/ |
- | root@735599480b45:/# | + | CMD [" |
- | search home | + | |
- | nameserver 8.8.8.8 | + | |
- | root@735599480b45:/# | + | |
</ | </ | ||
- | ou de passer une entrée pour le fichier **/ | + | Générez maintenant l' |
< | < | ||
- | root@735599480b45:/# | + | root@debian9: |
- | exit | + | Sending build context to Docker daemon |
- | root@debian9: | + | Step 1/6 : FROM centos: |
- | mongo2 | + | ---> 9f38484d220f |
- | root@debian9:~# docker rm mongo2 | + | Step 2/6 : MAINTAINER i2tch " |
- | mongo2 | + | ---> Running in 02c700ed04da |
- | root@debian9:~# docker run -it --name mongo2 | + | Removing intermediate container 02c700ed04da |
- | root@718e7eab814f: | + | ---> 4274107d52e2 |
- | 127.0.0.1 localhost | + | Step 3/6 : COPY myEntrypoint.sh /entrypoint.sh |
- | :: | + | ---> 7a3923372768 |
- | fe00::0 ip6-localnet | + | Step 4/6 : ENV myVariable 3 |
- | ff00::0 ip6-mcastprefix | + | ---> Running in 3288bf6291ad |
- | ff02::1 ip6-allnodes | + | Removing intermediate container 3288bf6291ad |
- | ff02::2 ip6-allrouters | + | ---> 3edb630c1511 |
- | 127.0.0.1 mickeymouse | + | Step 5/6 : ENTRYPOINT ["/ |
- | 172.17.0.2 718e7eab814f | + | ---> Running in 8dcba2c41520 |
+ | Removing intermediate container 8dcba2c41520 | ||
+ | ---> 11962052539c | ||
+ | Step 6/6 : CMD [" | ||
+ | ---> Running in f891fbcfaad0 | ||
+ | Removing intermediate container f891fbcfaad0 | ||
+ | ---> 7925ba23abb2 | ||
+ | Successfully built 7925ba23abb2 | ||
+ | Successfully tagged i2tch/ | ||
</ | </ | ||
- | ====Host==== | + | Lancez |
- | + | ||
- | 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, l' | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 2: enp0s3: < | + | mycommand (18:07:12) |
- | | + | mycommand (18:07:15) |
- | inet 10.0.2.15/ | + | mycommand (18:07:18) |
- | valid_lft 83772sec preferred_lft 83772sec | + | mycommand (18:07:21) |
- | inet6 fe80:: | + | ^Cmycommand (18:07:22) |
- | | + | mycommand (18:07:25) |
+ | mycommand (18:07:28) | ||
+ | ^P^Q | ||
+ | root@debian9:~/myDocker# | ||
</ | </ | ||
- | Démarrez un conteneur | + | Constatez que le conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [root@debian9 | + | CONTAINER ID IMAGE |
- | 1: lo: < | + | 140ecfdd80b7 |
- | link/loopback 00: | + | b3380889eb75 |
- | | + | d2ddb4f8ca8a |
- | valid_lft forever preferred_lft forever | + | c080793965de |
- | | + | root@debian9: |
- | valid_lft forever preferred_lft forever | + | root@debian9:~/myDocker# docker logs myDocker | tail |
- | 2: enp0s3: < | + | mycommand (18:08:25) |
- | | + | mycommand (18:08:28) |
- | inet 10.0.2.15/ | + | mycommand (18:08:31) |
- | | + | mycommand (18:08:34) |
- | inet6 fe80::a00: | + | mycommand (18:08:37) |
- | valid_lft forever preferred_lft forever | + | mycommand (18:08:40) |
- | 3: docker0: < | + | mycommand (18:08:43) |
- | | + | mycommand (18:08:46) |
- | inet 172.17.0.1/ | + | mycommand (18:08:49) |
- | | + | mycommand (18:08:52) |
- | inet6 fe80::42: | + | |
- | | + | |
- | [root@debian9 /]# hostname | + | |
- | debian9 | + | |
- | [root@debian9 /]# exit | + | |
</ | </ | ||
- | ====None==== | + | Arrêtez |
- | + | ||
- | Ce type de réseau est utilisé principalement dans le cas de l' | + | |
- | + | ||
- | Il est donc possible de lancer un conteneur | + | |
< | < | ||
- | root@718e7eab814f:/# | + | root@debian9: |
- | exit | + | myDocker |
- | root@debian9: | + | root@debian9: |
- | mongo2 | + | CONTAINER ID IMAGE |
- | root@debian9: | + | b3380889eb75 |
- | mongo2 | + | d2ddb4f8ca8a |
- | root@debian9: | + | c080793965de |
- | root@332aa9930f30:/# | + | |
</ | </ | ||
- | ====Liens==== | + | Démarrez |
- | + | ||
- | Le mécanisme des liens entre conteneurs est très puissant et permet d' | + | |
< | < | ||
- | root@332aa9930f30:/# | + | root@debian9: |
- | exit | + | myDocker |
- | + | root@debian9: | |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | 6a315259b2946c3bf2bb69f608cbe910d87edaadedb4f805e7a4dbf6af1eb916 | + | 140ecfdd80b7 |
- | + | b3380889eb75 | |
- | root@debian9: | + | d2ddb4f8ca8a |
- | CONTAINER ID IMAGE | + | c080793965de |
- | 6a315259b294 | + | </code> |
- | 332aa9930f30 | + | |
- | aaed3bc8e404 | + | |
- | 9f36a628c72b | + | |
- | 2169360fcbfd | + | |
- | ea239635e141 | + | |
- | 21b0490a93dd | + | |
- | bdb4bc0f81de | + | |
- | f5b45072b831 | + | |
- | 9731a48f126a | + | |
- | eacd70596e23 | + | |
- | cffb4456e9c4 | + | |
- | root@debian9:~# docker exec -it centos3 bash | + | Mettez le conteneur en pause : |
- | [root@6a315259b294 | + | < |
- | PING alias (172.17.0.4) 56(84) bytes of data. | + | root@debian9:~/myDocker# docker pause myDocker |
- | 64 bytes from alias (172.17.0.4): icmp_seq=1 ttl=64 time=0.116 ms | + | myDocker |
- | 64 bytes from alias (172.17.0.4): | + | root@debian9:~/myDocker# docker ps |
- | 64 bytes from alias (172.17.0.4): icmp_seq=3 ttl=64 time=0.068 ms | + | CONTAINER ID IMAGE |
- | 64 bytes from alias (172.17.0.4): icmp_seq=4 ttl=64 time=0.070 ms | + | 140ecfdd80b7 |
- | ^C | + | b3380889eb75 |
- | --- alias ping statistics --- | + | d2ddb4f8ca8a |
- | 4 packets transmitted, | + | c080793965de |
- | rtt min/ | + | |
- | + | ||
- | [root@6a315259b294 | + | |
- | 127.0.0.1 localhost | + | |
- | :: | + | |
- | fe00::0 ip6-localnet | + | |
- | ff00::0 ip6-mcastprefix | + | |
- | ff02:: | + | |
- | ff02:: | + | |
- | 172.17.0.4 alias aaed3bc8e404 centos2 | + | |
- | 172.17.0.2 6a315259b294 | + | |
- | + | ||
- | [root@6a315259b294 | + | |
- | exit | + | |
- | + | ||
- | root@debian9: | + | |
- | 172.17.0.2 | + | |
</ | </ | ||
- | Notez cependant qu le lien est unidirectionnel | + | Supprimez la pause : |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | myDocker | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 140ecfdd80b7 | ||
+ | b3380889eb75 | ||
+ | d2ddb4f8ca8a | ||
+ | c080793965de | ||
+ | </ | ||
- | [root@aaed3bc8e404 /]# ping centos3 | + | Lancez maintenant le conteneur avec un paramètre |
- | ping: centos3: Name or service not known | + | |
- | [root@aaed3bc8e404 | + | < |
- | PING 172.17.0.2 | + | root@debian9:~/myDocker# docker rm -fv myDocker |
- | 64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.054 ms | + | myDocker |
- | 64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.035 ms | + | root@debian9: |
- | 64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.051 ms | + | 0cf8c8c1bdf4cb05d9852900ecdf171ad9abad0fce29a9f040d5d8436285db65 |
- | 64 bytes from 172.17.0.2: icmp_seq=4 ttl=64 time=0.071 ms | + | root@debian9: |
- | ^C | + | Up and Running |
- | --- 172.17.0.2 ping statistics --- | + | Up and Running |
- | 4 packets transmitted, | + | Up and Running (18:13:39) |
- | rtt min/ | + | Up and Running (18:13:42) |
- | + | root@debian9:~/myDocker# | |
- | [root@aaed3bc8e404 | + | |
</ | </ | ||
- | Dans le cas ci-dessus, **centos2** peut atteindre **centos3** en utilisant l'adresse IP **172.17.0.2** car **centos2** se trouve dans les deux réseaux avec les adresses IP 172.17.0.4 et 172.25.0.3 | + | Changez la valeur de la variable d'environnement |
< | < | ||
- | [root@aaed3bc8e404 | + | root@debian9:~/myDocker# docker rm -fv myDocker |
- | exit | + | myDocker |
- | root@debian9: | + | root@debian9: |
- | 172.17.0.4172.25.0.3 | + | fbbe3b48c63310e37a3bad5fc962361c39c045a107f47980614efd6b2e8d3981 |
+ | root@debian9: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | mycommand (18: | ||
+ | root@debian9: | ||
</ | </ | ||
- | =====LAB #8 - Superviser les Conteneurs===== | + | ====2.2 - Bonnes Pratiques liées au Cache==== |
- | ====Les Journaux==== | + | ===Opérations Non-Idempotentes=== |
- | Consultez les logs d'un conteneur | + | Créez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@332aa9930f30: | + | root@debian9:~# mkdir bestp |
- | bash: ip: command not found | + | root@debian9:~# cd bestp |
- | root@332aa9930f30:/# ip address | + | root@debian9:~/bestp# vi Dockerfile |
- | bash: ip: command not found | + | root@debian9:~/bestp# cat Dockerfile |
- | root@332aa9930f30:/# ifconfig | + | FROM ubuntu:latest |
- | bash: ifconfig: command not found | + | RUN date +%N > /tmp/moment |
- | root@332aa9930f30:/# ls | + | ENTRYPOINT [" |
- | bin boot core data dev docker-entrypoint-initdb.d entrypoint.sh | + | CMD ["/tmp/ |
- | root@332aa9930f30:/# which ip | + | |
- | root@332aa9930f30:/# which ifconfig | + | |
- | root@332aa9930f30: | + | |
- | bash: docker: command not found | + | |
- | root@332aa9930f30: | + | |
- | exit | + | |
</ | </ | ||
- | ====Les Processus==== | + | 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. | ||
+ | </ | ||
- | Consultez les processus d'un conteneur | + | Compilez l'image : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | UID | + | Sending build context to Docker daemon |
- | root 31073 | + | 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 ["/tmp/ | ||
+ | | ||
+ | Removing intermediate container 48974dc12faa | ||
+ | | ||
+ | Successfully built c55a42a18572 | ||
+ | Successfully tagged testcache: | ||
+ | root@debian9: | ||
</ | </ | ||
- | ====L' | + | Exécuter maintenant un premier conteneur à partir de l'image compilée |
- | + | ||
- | Pour voir l'activité d'un conteneur, utilisez la commande suivante | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER | + | 369009216 |
- | centos3 | + | |
</ | </ | ||
- | =====LAB #9 - Gestion des Ressources===== | + | Supprimez maintenant le conteneur |
- | + | ||
- | La gestion de base des ressources allouées à un conteneur | + | |
- | + | ||
- | * --memory | + | |
- | * --cpu-shares | + | |
- | + | ||
- | 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 > / | ||
+ | ---> Using cache | ||
+ | | ||
+ | Step 3/4 : ENTRYPOINT ["more"] | ||
+ | ---> Using cache | ||
+ | | ||
+ | Step 4/4 : CMD ["/ | ||
+ | | ||
+ | | ||
+ | Successfully built c55a42a18572 | ||
+ | Successfully tagged testcache: | ||
+ | root@debian9: | ||
</ | </ | ||
- | 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 | + | 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 | + | |
- | </ | + | |
- | </ | + |