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:drf01 [2020/06/26 11:40] – admin | elearning:workbooks:docker1:drf01 [2022/12/15 16:44] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
~~PDF: | ~~PDF: | ||
- | Version : **2020.01** | + | Version : **2022.01** |
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======DOF102 - Gérer les Images | + | ======DOF102 - Démarrer avec Docker====== |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **DOF102 - Gérer et Stocker les Images | + | * **DOF102 - Démarrer avec Docker** |
- | * LAB #4 - Re-créer | + | * Contenu du Module |
- | * Utilisation | + | * Présentation de Docker |
- | * FROM | + | * LAB #1 - Travailler avec Docker |
- | * RUN | + | * 1.1 - Installer docker |
- | * ENV | + | * 1.2 - Démarrer un Conteneur |
- | * VOLUME | + | * 1.3 - Consulter la Liste des Conteneurs et Images |
- | * COPY | + | * 1.4 - Rechercher une Image dans un Dépôt |
- | * ENTRYPOINT | + | * 1.5 - Supprimer un Conteneur d'une Image |
- | * EXPOSE | + | * 1.6 - Créer une Image à partir |
- | * CMD | + | * 1.7 - Supprimer une Image |
- | * Autres Commandes | + | * 1.8 - Créer un Conteneur avec un Nom Spécifique |
- | * LAB #5 - Créer | + | * 1.9 - Exécuter une Commande dans un Conteneur |
- | * Création et test du script | + | * 1.10 - Injecter des Variables d' |
- | * Bonnes Pratiques liées | + | * 1.11 - Modifier le Nom d' |
+ | * 1.12 - Mapper des Ports d'un Conteneur | ||
+ | * 1.13 - Démarrer un Conteneur en mode Détaché | ||
+ | * 1.14 - Accéder aux Services d'un Conteneur de l' | ||
+ | * 1.15 - Arrêter et Démarrer un Conteneur | ||
+ | * 1.16 - Utiliser des Signaux avec un Conteneur | ||
+ | * 1.17 - Forcer la Suppression d'un Conteneur en cours d' | ||
+ | * 1.18 - Utilisation Simple d'un Volume | ||
+ | * 1.19 - Télécharger une image sans créer un conteneur | ||
+ | * 1.20 - S' | ||
+ | * 1.21 - Installer un logiciel dans le conteneur | ||
+ | * 1.22 - Utilisation de la commande docker commit | ||
+ | * 1.23 - Se connecter | ||
- | =====LAB #4 - Re-créer une image officielle docker===== | + | =====Présentation de Docker===== |
- | ====Utilisation | + | La virtualisation classique nécessite l' |
- | Bien que la compilation des images soient assuré par Docker Hub, il est tout à fait possible de compiler une image " | + | {{ :elearning: |
- | < | + | Docker est une application de virtualisation légère qui utilise des **images** et des **conteneurs**. |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | </ | + | |
- | Le Docker file contient les instructions nécessaires pour la contruction de l'image : | + | Une **image** est un paquet exécutable contenant tout ce qu'il est nécessaire afin d' |
- | <file txt Dockerfile> | + | * le code |
- | FROM ubuntu: | + | * un runtime |
+ | * des bibliothèques, | ||
+ | * des variables d' | ||
+ | * des fichiers de configuration | ||
- | # add our user and group first to make sure their IDs get assigned consistently, | + | Un **conteneur** est une instance de l' |
- | RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | + | |
- | RUN set -eux; \ | + | Les conteneurs exécutent des applications nativement en utilisant le noyau de la machine hôte. De ce fait les performances d'un conteneur sont supérieures à celles d'une machine virtuelle qui doit passer par un hyperviseur pour accéder aux ressources de la machine hôte. |
- | 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:// | + | {{ :elearning:workbooks: |
- | ENV GOSU_VERSION 1.11 | + | |
- | # grab " | + | |
- | ENV JSYAML_VERSION 3.13.0 | + | |
- | RUN set -ex; \ | + | Docker existe en deux versions **Docker-CE** (Docker Community Edition) et **Docker-EE** (Docker Enterprise Edition). Pour consulter les différences entre les deux versions, consultez le lien **[[https://docs.docker.com/engine/installation/]]**. |
- | \ | + | |
- | 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 / | + | Pour gérer le système de fichiers du conteneur, Docker utilisait au départ le filesystem AUFS. AUFS est un système de fichiers de la famille UnionFS. Un système de fichier de type UnionFS assemble des repertoires multiples les uns sur les autres pour ensuite les présenter sous forme d'un repertoire unique contenant les objets les plus récents grâce à un union mount. Les repertoires sous AUFS sont appelés des **branches** et se trouvent dans **/ |
- | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B | + | {{ : |
- | 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 | + | |
- | rm -r " | + | |
- | apt-key list | + | |
- | # Allow build-time overrides (eg. to build image with MongoDB Enterprise version) | + | Le système de fichiers AUFS a été ensuite remplacé dans Docker par le système de fichiers **OverlayFS**. Ce système de fichiers combine deux répertoires appelés **Layers**. Le layer inférieur porte le nom **lowerdir** tandis que le niveau au dessus est appelé le **upperdir**. La vue unifiée porte le nom **merged**. Dans le cas où les layers de conteneur et de l' |
- | # 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 | + | {{ :elearning:workbooks: |
- | ENV MONGO_VERSION 4.1.9 | + | |
- | # bashbrew-architectures:amd64 arm64v8 s390x | + | |
- | RUN echo "deb http:// | + | |
- | RUN set -x \ | + | Le système de fichiers OverlayFS ne sait gérer que deux niveaux. Ceci implique une utilisation excessive d' |
- | && 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 /var/lib/apt/lists/* \ | + | |
- | && rm -rf / | + | |
- | && mv / | + | |
- | RUN mkdir -p /data/db / | + | Cette limitation a donné lieu à l' |
- | && chown -R mongodb: | + | |
- | VOLUME /data/db / | + | |
- | COPY docker-entrypoint.sh / | + | =====LAB #1 - Travailler avec Docker===== |
- | ENTRYPOINT [" | + | |
- | EXPOSE 27017 | + | ====1.1 - Installer docker==== |
- | CMD [" | + | |
- | </ | + | |
- | Le fichier | + | Docker n'est pas dans le dépôts de Debian. Afin de l' |
- | <file txt docker-entrypoint.sh> | + | <code> |
- | #!/bin/bash | + | root@debian9: |
- | set -Eeuo pipefail | + | ... |
+ | root@debian9: | ||
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | ca-certificates is already the newest version. | ||
+ | ca-certificates | ||
+ | gnupg2 is already the newest version. | ||
+ | gnupg2 set to manually installed. | ||
+ | The following extra packages will be installed: | ||
+ | libcurl3 python3-dbus python3-software-properties unattended-upgrades | ||
+ | Suggested packages: | ||
+ | python-dbus-doc python3-dbus-dbg | ||
+ | The following NEW packages will be installed: | ||
+ | apt-transport-https curl libcurl3 python3-dbus python3-software-properties | ||
+ | software-properties-common unattended-upgrades | ||
+ | 0 upgraded, 7 newly installed, 0 to remove and 1 not upgraded. | ||
+ | Need to get 960 kB of archives. | ||
+ | After this operation, 2,344 kB of additional disk space will be used. | ||
+ | Do you want to continue? [Y/n] | ||
+ | </ | ||
- | if [ "${1:0:1}" = ' | + | Téléchargez la clef GPG officielle de docker |
- | set -- mongod " | + | |
- | fi | + | |
- | originalArgOne=" | + | < |
+ | root@debian9: | ||
+ | OK | ||
+ | </ | ||
- | # allow the container to be started with `--user` | + | Vérifiez que l'ID de la clef est **9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88** : |
- | # 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 " | + | root@debian9: |
- | chown --dereference mongodb "/proc/$$/fd/1" "/ | + | /etc/apt/trusted.gpg |
- | # ignore errors thanks to https://github.com/docker-library/mongo/ | + | -------------------- |
+ | pub 4096R/0EBFCD88 2017-02-22 | ||
+ | Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 | ||
+ | uid Docker Release (CE deb) < | ||
+ | sub 4096R/F273FCD8 2017-02-22 | ||
+ | ... | ||
+ | </code> | ||
- | exec gosu mongodb " | + | Ajoutez le dépôt **stable** de docker : |
- | fi | + | |
- | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | + | < |
- | # https://docs.mongodb.com/manual/administration/ | + | root@debian9: |
- | if [[ "$originalArgOne" | + | </code> |
- | numa=' | + | |
- | if $numa true &> /dev/null; then | + | |
- | set -- $numa " | + | |
- | fi | + | |
- | fi | + | |
- | # usage: file_env VAR [DEFAULT] | + | <WRAP center round important> |
- | # ie: file_env ' | + | **Important** |
- | # (will allow for " | + | </WRAP> |
- | # " | + | |
- | file_env() { | + | |
- | local var=" | + | |
- | local fileVar=" | + | |
- | local def=" | + | |
- | if [ " | + | |
- | echo | + | |
- | exit 1 | + | |
- | fi | + | |
- | local val=" | + | |
- | if [ " | + | |
- | val=" | + | |
- | elif [ " | + | |
- | val=" | + | |
- | fi | + | |
- | export " | + | |
- | unset " | + | |
- | } | + | |
- | # see https:// | + | Installez maintenant le paquet **docker-ce** : |
- | _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() { | + | root@debian9: |
- | jq --null-input --arg ' | + | ... |
- | } | + | root@debian9: |
+ | Reading package lists... Done | ||
+ | Building dependency tree | ||
+ | Reading state information... Done | ||
+ | The following extra packages will be installed: | ||
+ | aufs-tools cgroupfs-mount git git-man libapparmor1 liberror-perl | ||
+ | libnih-dbus1 libnih1 makedev mountall plymouth rsync | ||
+ | Suggested packages: | ||
+ | git-daemon-run git-daemon-sysvinit git-doc git-el git-email git-gui gitk | ||
+ | gitweb git-arch git-cvs git-mediawiki git-svn plymouth-themes | ||
+ | The following NEW packages will be installed: | ||
+ | aufs-tools cgroupfs-mount docker-ce git git-man libapparmor1 liberror-perl | ||
+ | libnih-dbus1 libnih1 makedev mountall plymouth rsync | ||
+ | 0 upgraded, 13 newly installed, 0 to remove and 99 not upgraded. | ||
+ | Need to get 26.5 MB of archives. | ||
+ | After this operation, 123 MB of additional disk space will be used. | ||
+ | Do you want to continue? [Y/n] | ||
+ | </ | ||
- | jsonConfigFile=" | + | Dernièrement, |
- | tempConfigFile=" | + | |
- | _parse_config() { | + | |
- | if [ -s " | + | |
- | return 0 | + | |
- | fi | + | |
- | local configPath | + | < |
- | if configPath=" | + | root@debian9:~# docker version |
- | # if --config is specified, parse it into a JSON file so we can remove a few problematic keys (especially SSL-related keys) | + | Client: Docker Engine |
- | # see https://docs.mongodb.com/ | + | Version: 19.03.4 |
- | mongo --norc --nodb --quiet --eval " | + | API version: |
- | jq 'del(.systemLog, | + | Go version: |
- | return 0 | + | Git commit: |
- | fi | + | Built: |
+ | | ||
+ | | ||
- | return 1 | + | Server: Docker Engine - Community |
- | } | + | Engine: |
- | dbPath= | + | |
- | _dbPath() { | + | API version: |
- | if [ -n " | + | Go version: |
- | echo " | + | Git commit: |
- | return | + | Built: |
- | fi | + | OS/ |
+ | Experimental: | ||
+ | | ||
+ | Version: | ||
+ | GitCommit: | ||
+ | | ||
+ | Version: | ||
+ | GitCommit: | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
- | if ! dbPath=" | + | Docker est composé de trois éléments : un serveur, un client et un ou plusieur Repositories ou Dépôts : |
- | 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 | + | |
- | : " | + | ====1.2 - Démarrer un Conteneur==== |
- | echo " | + | Démarrez un conteneur de l' |
- | } | + | |
- | if [ " | + | < |
- | file_env ' | + | root@debian9: |
- | file_env ' | + | Unable |
- | # pre-check a few factors | + | latest: Pulling from library/ |
- | shouldPerformInitdb= | + | 1b930d010525: |
- | if [ " | + | Digest: sha256: |
- | # if we have a username/ | + | Status: Downloaded newer image for hello-world:latest |
- | _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 " | + | Hello from Docker! |
- | # if we've got any / | + | This message shows that your installation appears |
- | 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) | + | To generate this message, Docker took the following steps: |
- | if [ -n "$shouldPerformInitdb" | + | 1. The Docker client contacted the Docker daemon. |
- | dbPath=" | + | 2. The Docker daemon pulled the "hello-world" |
- | for path in \ | + | (amd64) |
- | " | + | 3. The Docker daemon created a new container from that image which runs the |
- | " | + | |
- | " | + | 4. The Docker daemon streamed that output to the Docker client, which sent it |
- | " | + | to your terminal. |
- | ; do | + | |
- | if [ -e " | + | |
- | shouldPerformInitdb= | + | |
- | break | + | |
- | fi | + | |
- | done | + | |
- | fi | + | |
- | if [ -n " | + | To try something more ambitious, you can run an Ubuntu container with: |
- | mongodHackedArgs=( "$@" ) | + | |
- | if _parse_config " | + | |
- | _mongod_hack_ensure_arg_val | + | |
- | 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 " | + | Share images, automate workflows, |
- | # https://github.com/docker-library/ | + | |
- | _mongod_hack_ensure_no_arg --auth " | + | |
- | if [ " | + | |
- | _mongod_hack_ensure_no_arg_val --replSet " | + | |
- | fi | + | |
- | sslMode=" | + | For more examples and ideas, visit: |
- | _mongod_hack_ensure_arg_val --sslMode " | + | https:// |
+ | </ | ||
- | if stat "/ | + | <WRAP center round important> |
- | # https:// | + | **Important** |
- | # https:// | + | </WRAP> |
- | _mongod_hack_ensure_arg_val --logpath "/ | + | |
- | else | + | |
- | initdbLogPath=" | + | |
- | echo | + | |
- | _mongod_hack_ensure_arg_val --logpath " | + | |
- | fi | + | |
- | _mongod_hack_ensure_arg --logappend " | + | |
- | pidfile=" | + | Démarrez un conteneur de l' |
- | rm -f " | + | |
- | _mongod_hack_ensure_arg_val --pidfilepath " | + | |
- | " | + | < |
+ | root@debian9:~# docker run -it ubuntu bash | ||
+ | Unable to find image ' | ||
+ | latest: Pulling from library/ | ||
+ | 898c46f3b1a1: | ||
+ | 63366dfa0a50: | ||
+ | 041d4cd74a92: | ||
+ | 6e1bee0f8701: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for ubuntu: | ||
+ | root@3a3f9bda6cbd:/# | ||
+ | bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var | ||
+ | root@3a3f9bda6cbd:/# | ||
+ | DISTRIB_ID=Ubuntu | ||
+ | DISTRIB_RELEASE=18.04 | ||
+ | DISTRIB_CODENAME=bionic | ||
+ | DISTRIB_DESCRIPTION=" | ||
+ | </ | ||
- | mongo=( mongo --host 127.0.0.1 --port 27017 --quiet ) | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | # check to see that our " | + | Consulter la liste des paquets installés dans le conteneur ubuntu |
- | # 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 "error: $originalArgOne does not appear to have accepted connections quickly enough -- perhaps it had an error?" | + | |
- | echo >& | + | |
- | exit 1 | + | |
- | fi | + | |
- | sleep 1 | + | |
- | done | + | |
- | if [ " | + | < |
- | rootAuthDatabase=' | + | root@835001339e79:/# |
+ | Desired=Unknown/ | ||
+ | | Status=Not/ | ||
+ | |/ Err? | ||
+ | ||/ Name | ||
+ | +++-====================================-=======================-=======================-============================================================================= | ||
+ | ii adduser | ||
+ | ii apt 1.6.8 | ||
+ | ii base-files | ||
+ | ii base-passwd | ||
+ | ii bash | ||
+ | ii bsdutils | ||
+ | ii bzip2 1.0.6-8.1 | ||
+ | ii coreutils | ||
+ | ii dash | ||
+ | ii debconf | ||
+ | ii debianutils | ||
+ | ii diffutils | ||
+ | ii dpkg | ||
+ | ii e2fsprogs | ||
+ | ii fdisk 2.31.1-0.4ubuntu3.3 | ||
+ | ii findutils | ||
+ | ii gcc-8-base: | ||
+ | ii gpgv | ||
+ | ii grep | ||
+ | ii gzip | ||
+ | ii hostname | ||
+ | ii init-system-helpers | ||
+ | ii libacl1: | ||
+ | ii libapt-pkg5.0: | ||
+ | ii libattr1: | ||
+ | ii libaudit-common | ||
+ | ii libaudit1: | ||
+ | ii libblkid1: | ||
+ | ii libbz2-1.0: | ||
+ | ii libc-bin | ||
+ | ii libc6: | ||
+ | ii libcap-ng0: | ||
+ | ii libcom-err2: | ||
+ | ii libdb5.3: | ||
+ | ii libdebconfclient0: | ||
+ | ii libext2fs2: | ||
+ | ii libfdisk1: | ||
+ | ii libffi6: | ||
+ | ii libgcc1: | ||
+ | ii libgcrypt20: | ||
+ | ii libgmp10: | ||
+ | ii libgnutls30: | ||
+ | ii libgpg-error0: | ||
+ | ii libhogweed4: | ||
+ | ii libidn2-0: | ||
+ | ii liblz4-1: | ||
+ | ii liblzma5: | ||
+ | ii libmount1: | ||
+ | ii libncurses5: | ||
+ | ii libncursesw5: | ||
+ | ii libnettle6: | ||
+ | ii libp11-kit0: | ||
+ | ii libpam-modules: | ||
+ | ii libpam-modules-bin | ||
+ | ii libpam-runtime | ||
+ | ii libpam0g: | ||
+ | ii libpcre3: | ||
+ | ii libprocps6: | ||
+ | ii libseccomp2: | ||
+ | ii libselinux1: | ||
+ | ii libsemanage-common | ||
+ | ii libsemanage1: | ||
+ | ii libsepol1: | ||
+ | ii libsmartcols1: | ||
+ | ii libss2: | ||
+ | ii libstdc++6: | ||
+ | ii libsystemd0: | ||
+ | ii libtasn1-6: | ||
+ | ii libtinfo5: | ||
+ | ii libudev1: | ||
+ | ii libunistring2: | ||
+ | ii libuuid1: | ||
+ | ii libzstd1: | ||
+ | ii login 1: | ||
+ | ii lsb-base | ||
+ | ii mawk | ||
+ | ii mount 2.31.1-0.4ubuntu3.3 | ||
+ | ii ncurses-base | ||
+ | ii ncurses-bin | ||
+ | ii passwd | ||
+ | ii perl-base | ||
+ | ii procps | ||
+ | ii sed 4.4-2 | ||
+ | ii sensible-utils | ||
+ | ii sysvinit-utils | ||
+ | ii tar 1.29b-2ubuntu0.1 | ||
+ | ii ubuntu-keyring | ||
+ | ii util-linux | ||
+ | ii zlib1g: | ||
+ | root@835001339e79:/# | ||
+ | exit | ||
+ | root@debian9: | ||
+ | </ | ||
- | " | + | Les options de la commande docker run peuvent être visualisées avec la commande |
- | db.createUser({ | + | |
- | user: $(_js_escape " | + | |
- | pwd: $(_js_escape " | + | |
- | roles: [ { role: ' | + | |
- | }) | + | |
- | EOJS | + | |
- | fi | + | |
- | export MONGO_INITDB_DATABASE=" | + | < |
+ | root@debian9:~# docker run --help | ||
- | echo | + | Usage: docker |
- | for f in /docker-entrypoint-initdb.d/*; do | + | |
- | case " | + | |
- | *.sh) echo "$0: running $f"; | + | |
- | *.js) echo "$0: running $f"; " | + | |
- | *) | + | |
- | esac | + | |
- | echo | + | |
- | done | + | |
- | " | + | Run a command in a new container |
- | rm -f " | + | |
- | echo | + | Options: |
- | echo ' | + | |
- | echo | + | -a, --attach list Attach to STDIN, STDOUT or STDERR |
- | fi | + | --blkio-weight uint16 |
+ | --blkio-weight-device list Block IO weight (relative device weight) (default []) | ||
+ | --cap-add list Add Linux capabilities | ||
+ | --cap-drop list Drop Linux capabilities | ||
+ | --cgroup-parent string | ||
+ | --cidfile string | ||
+ | --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period | ||
+ | --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota | ||
+ | --cpu-rt-period int Limit CPU real-time period in microseconds | ||
+ | --cpu-rt-runtime int Limit CPU real-time runtime in microseconds | ||
+ | -c, --cpu-shares int CPU shares (relative weight) | ||
+ | --cpus decimal | ||
+ | --cpuset-cpus string | ||
+ | --cpuset-mems string | ||
+ | -d, --detach | ||
+ | --detach-keys string | ||
+ | --device list Add a host device to the container | ||
+ | --device-cgroup-rule list Add a rule to the cgroup allowed devices list | ||
+ | --device-read-bps list Limit read rate (bytes per second) from a device (default []) | ||
+ | --device-read-iops list Limit read rate (IO per second) from a device (default []) | ||
+ | --device-write-bps list Limit write rate (bytes per second) to a device (default []) | ||
+ | --device-write-iops list Limit write rate (IO per second) to a device (default []) | ||
+ | --disable-content-trust | ||
+ | --dns list Set custom DNS servers | ||
+ | --dns-option list Set DNS options | ||
+ | --dns-search list Set custom DNS search domains | ||
+ | --entrypoint string | ||
+ | -e, --env list Set environment variables | ||
+ | --env-file list Read in a file of environment variables | ||
+ | --expose list Expose a port or a range of ports | ||
+ | --group-add list Add additional groups to join | ||
+ | --health-cmd string | ||
+ | --health-interval duration | ||
+ | --health-retries int | ||
+ | --health-start-period duration | ||
+ | --health-timeout duration | ||
+ | --help | ||
+ | -h, --hostname string | ||
+ | --init | ||
+ | -i, --interactive | ||
+ | --ip string | ||
+ | --ip6 string | ||
+ | --ipc string | ||
+ | --isolation string | ||
+ | --kernel-memory bytes Kernel memory limit | ||
+ | -l, --label list Set meta data on a container | ||
+ | --label-file list Read in a line delimited file of labels | ||
+ | --link list Add link to another container | ||
+ | --link-local-ip list | ||
+ | --log-driver string | ||
+ | --log-opt list Log driver options | ||
+ | --mac-address string | ||
+ | -m, --memory bytes | ||
+ | --memory-reservation bytes | ||
+ | --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap | ||
+ | --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) | ||
+ | --mount mount Attach a filesystem mount to the container | ||
+ | --name string | ||
+ | --network string | ||
+ | --network-alias list Add network-scoped alias for the container | ||
+ | --no-healthcheck | ||
+ | --oom-kill-disable | ||
+ | --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) | ||
+ | --pid string | ||
+ | --pids-limit int Tune container pids limit (set -1 for unlimited) | ||
+ | --privileged | ||
+ | -p, --publish list | ||
+ | -P, --publish-all | ||
+ | --read-only | ||
+ | --restart string | ||
+ | --rm | ||
+ | --runtime string | ||
+ | --security-opt list Security Options | ||
+ | --shm-size bytes Size of /dev/shm | ||
+ | --sig-proxy | ||
+ | --stop-signal string | ||
+ | --stop-timeout int | ||
+ | --storage-opt list | ||
+ | --sysctl map | ||
+ | --tmpfs list Mount a tmpfs directory | ||
+ | -t, --tty Allocate a pseudo-TTY | ||
+ | --ulimit ulimit | ||
+ | -u, --user string | ||
+ | --userns string | ||
+ | --uts string | ||
+ | -v, --volume list Bind mount a volume | ||
+ | --volume-driver string | ||
+ | --volumes-from list Mount volumes from the specified container(s) | ||
+ | -w, --workdir string | ||
+ | </ | ||
- | # MongoDB 3.6+ defaults to localhost-only binding | + | ====1.3 - Consulter la Liste des Conteneurs et Images==== |
- | 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 " | + | Pour consulter tous les conteneurs, utilisez la commande **docker ps** avec l' |
- | fi | + | |
- | rm -f "$jsonConfigFile" "$tempConfigFile" | + | < |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 3a3f9bda6cbd | ||
+ | 26ef17bd115d | ||
+ | </ | ||
- | exec " | + | <WRAP center round important> |
- | </file> | + | **Important** - Notez que chaque conteneur peut être référencé par son **CONTAINER ID** ou par son **NAME**. |
+ | </WRAP> | ||
- | Examinons chaque | + | Pour consulter la liste des images, utilisez la commande |
- | ====FROM==== | + | < |
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </ | ||
- | <file> | + | <WRAP center round important> |
- | FROM ubuntu: | + | **Important** - Notez que chaque image est référencée par son IMAGE ID. |
- | </file> | + | </WRAP> |
- | Cette ligne définit l' | + | ====1.4 - Rechercher |
- | ====RUN==== | + | Pour rechercher une image docker dans le dépôt par défaut, utilisez la commande **docker search** : |
- | <file> | + | <code> |
- | ... | + | root@debian9: |
+ | NAME DESCRIPTION | ||
+ | centos | ||
+ | ansible/ | ||
+ | jdeathe/ | ||
+ | consol/ | ||
+ | imagine10255/ | ||
+ | centos/ | ||
+ | tutum/ | ||
+ | gluster/ | ||
+ | openshift/ | ||
+ | centos/ | ||
+ | centos/ | ||
+ | kinogmt/ | ||
+ | centos/ | ||
+ | centos/ | ||
+ | openshift/ | ||
+ | pivotaldata/ | ||
+ | openshift/ | ||
+ | </ | ||
- | RUN groupadd | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | RUN set -eux; \ | + | ====1.5 - Supprimer un Conteneur d'une Image==== |
- | 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 / | + | Pour supprimer un conteneur |
- | ... | + | |
- | RUN set -ex; \ | + | < |
- | export GNUPGHOME="$(mktemp -d)"; \ | + | root@debian9: |
- | for key in $GPG_KEYS; do \ | + | CONTAINER ID IMAGE |
- | gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys | + | 3a3f9bda6cbd |
- | done; \ | + | 26ef17bd115d |
- | gpg --batch --export $GPG_KEYS > / | + | root@debian9:~# docker |
- | command -v gpgconf && gpgconf --kill all || :; \ | + | wizardly_buck |
- | rm -r " | + | root@debian9: |
- | apt-key list | + | CONTAINER ID IMAGE |
- | ... | + | 26ef17bd115d |
- | RUN set -x \ | + | root@debian9: |
- | && apt-get update \ | + | REPOSITORY |
- | && apt-get install -y \ | + | ubuntu |
- | ${MONGO_PACKAGE}=$MONGO_VERSION \ | + | hello-world |
- | ${MONGO_PACKAGE}-server=$MONGO_VERSION \ | + | </code> |
- | ${MONGO_PACKAGE}-shell=$MONGO_VERSION \ | + | |
- | ${MONGO_PACKAGE}-mongos=$MONGO_VERSION \ | + | |
- | ${MONGO_PACKAGE}-tools=$MONGO_VERSION \ | + | |
- | && rm -rf /var/ | + | |
- | && rm -rf / | + | |
- | && mv / | + | |
- | RUN mkdir -p /data/db / | + | <WRAP center round important> |
- | && chown -R mongodb: | + | **Important** |
- | ... | + | </WRAP> |
- | </file> | + | |
- | Cette commande lance un processus dans la construction de l' | + | ====1.6 -Créer une Image à partir d'un Conteneur Modifié=== |
- | Il existe | + | Modifier |
- | RUN ["/bin/bash", "-c", " | + | < |
+ | root@debian9: | ||
+ | root@54b0dae2f3a9: | ||
+ | bin | ||
+ | root@54b0dae2f3a9: | ||
+ | root@54b0dae2f3a9:/# | ||
+ | bin boot dev etc lib lib64 media mnt opt proc root run sbin srv sys tmp usr var | ||
+ | root@54b0dae2f3a9:/# | ||
+ | exit | ||
+ | root@debian9: | ||
+ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ====ENV==== | + | Consultez la différence entre le conteneur et l' |
- | Cette commande permet de fixer la valeur d'une variable d' | + | < |
+ | root@debian9:~# docker ps -a | ||
+ | CONTAINER ID IMAGE | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | C /root | ||
+ | A / | ||
+ | D /home | ||
+ | </ | ||
- | <file> | + | <WRAP center round important> |
- | ... | + | **Important** |
- | ENV GOSU_VERSION 1.11 | + | </WRAP> |
- | # grab "js-yaml" for parsing mongod' | + | |
- | ENV JSYAML_VERSION 3.13.0 | + | |
- | ... | + | |
- | ENV GPG_KEYS E162F504A20CDF15827F718D4B7C549A058F8B6B | + | Créez un autre conteneur à partir de l' |
- | ... | + | |
- | ENV MONGO_PACKAGE=${MONGO_PACKAGE} MONGO_REPO=${MONGO_REPO} | + | < |
+ | root@debian9: | ||
+ | root@92f0d4bb7967:/# | ||
+ | bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var | ||
+ | root@92f0d4bb7967:/# | ||
+ | exit | ||
+ | root@debian9: | ||
+ | </ | ||
- | ENV MONGO_MAJOR 4.1 | + | <WRAP center round important> |
- | ENV MONGO_VERSION 4.1.95 | + | **Important** - Dans ce nouveau conteneur, le répertoire **/home** est présent compte tenu du fait qu'il a été généré à partir de l' |
- | ... | + | </WRAP> |
- | </file> | + | |
- | **et** dans les conteneurs générés | + | Créez maintenant l' |
- | ====VOLUME==== | + | < |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | sha256: | ||
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | ubuntu_1 | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </ | ||
- | < | + | ====1.7 - Supprimer une Image==== |
- | ... | + | |
- | VOLUME /data/db / | + | |
- | ... | + | |
- | </ | + | |
- | Cette commande expose les répertoires passés en argument afin qu'ils puissent être mappés vers des répertoires sur la machine hôte ou ailleurs, tel que nous avons vu avec l' | + | Créez maintenant un conteneur à partir de la nouvelle image **ubuntu_1** : |
- | ====COPY==== | + | < |
+ | root@debian9: | ||
+ | root@904215fb79b4:/# | ||
+ | bin boot dev etc lib lib64 media mnt opt proc root run sbin srv sys tmp usr var | ||
+ | root@904215fb79b4:/# | ||
+ | exit | ||
+ | root@debian9: | ||
+ | </ | ||
- | <file> | + | <WRAP center round important> |
- | ... | + | **Important** |
- | COPY docker-entrypoint.sh / | + | </WRAP> |
- | ... | + | |
- | </file> | + | |
- | Cette commande permet | + | Essayez |
- | Rappelez-vous de l' | + | < |
- | + | root@debian9:~# docker rmi ubuntu_1 | |
- | Il est possible d' | + | Error response from daemon: conflict: unable to remove repository reference " |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 904215fb79b4 | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** - Il existe une autre commande similaire à COPY : ADD. ADD est une commande qui n' | + | **Important** - Notez qu' |
</ | </ | ||
- | ====ENTRYPOINT==== | + | Supprimez donc le conteneur **priceless_swirles** ainsi que l' |
- | <file> | + | <code> |
- | ... | + | root@debian9: |
- | ENTRYPOINT ["docker-entrypoint.sh"] | + | priceless_swirles |
- | ... | + | root@debian9: |
- | </file> | + | CONTAINER ID IMAGE |
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | Untagged: ubuntu_1: | ||
+ | Deleted: sha256: | ||
+ | Deleted: sha256: | ||
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | ubuntu | ||
+ | hello-world | ||
+ | </code> | ||
- | Cette commande stipule la commande qui sera exécutée lors du démarrage du conteneur. | + | Pour pouvoir supprimer tous les conteneurs, listez-les par leur **Container ID** : |
- | Deux cas de figure se présentent | + | < |
+ | root@debian9:~# docker ps -aq | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | </ | ||
- | * ENTRYPOINT suivi d'une chaîne - un shell est démarré pour exécuter la chaîne, | + | Supprimer toutes les conteneurs : |
- | * ENTRYPOINT suivi d'une table JSON ( comme ci-dessus ) au format ENTRYPOINT [" | + | |
- | Dans le fichier **docker-entrypoint.sh** | + | < |
+ | root@debian9: | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | root@debian9:~# | ||
+ | </ | ||
- | < | + | Pour supprimer un conteneur dès la fin de son exécution, utilisez l' |
- | ... | + | |
- | originalArgOne=" | + | |
- | # allow the container to be started with `--user` | + | < |
- | # all mongo* commands should be dropped to the correct user | + | root@debian9: |
- | if [[ " | + | root@d123b0112fc2:/ |
- | if [ " | + | bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var |
- | find | + | root@d123b0112fc2: |
- | fi | + | exit |
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | </ | ||
- | # make sure we can write to stdout and stderr as " | + | ====1.8 - Créer un Conteneur avec un Nom Spécifique==== |
- | # (for our " | + | |
- | chown --dereference mongodb "/ | + | |
- | # ignore errors thanks to https:// | + | |
- | exec gosu mongodb " | + | Créez maintenant un conteneur avec un nom spécifique : |
- | fi | + | |
- | # you should use numactl to start your mongod instances, including the config servers, mongos instances, and any clients. | + | < |
- | # https:// | + | root@debian9:~# docker run -it --name=i2tch ubuntu |
- | if [[ " | + | root@04b5ab87539a:/# |
- | numa=' | + | bin boot |
- | if $numa true &> /dev/null; then | + | root@04b5ab87539a:/# |
- | set -- $numa "$@" | + | exit |
- | fi | + | root@debian9: |
- | fi | + | CONTAINER ID IMAGE |
- | ... | + | 04b5ab87539a |
- | exec "$@" | + | </code> |
- | </file> | + | |
- | si la valeur du paramètre passé à entrypoint.sh est **mongod**, le script affecte l' | + | Pour obtenir de l' |
- | + | ||
- | Ce fichier finit par " | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | mongo2 | + | [ |
- | root@debian9:~/mongodb# | + | { |
- | root@a2b3a0f53f62:/# pwd | + | " |
- | / | + | " |
- | root@a2b3a0f53f62:/# exit | + | " |
- | exit | + | " |
- | root@debian9:~/mongodb# | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | 0, | ||
+ | 0 | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | ], | ||
+ | " | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | ] | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "PATH=/usr/ | ||
+ | ], | ||
+ | " | ||
+ | "/ | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | ] | ||
</ | </ | ||
- | <WRAP center round important> | + | ====1.9 |
- | **Important** | + | |
- | </ | + | |
- | ====EXPOSE==== | + | Pour exécuter une commande spécifique dans un conteneur, passez la commande en argument : |
- | <file> | + | <code> |
- | ... | + | root@debian9: |
- | EXPOSE 27017 | + | PATH=/ |
- | ... | + | HOSTNAME=77bb110031aa |
- | </file> | + | HOME=/root |
+ | root@debian9: | ||
+ | </code> | ||
- | Cette commande permet | + | ====1.10 - Injecter des Variables |
+ | |||
+ | Pour injecter une ou des variables d'environnement dans un conteneur, utilisez un fichier pré-établi | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | mongo2 | + | root@debian9: |
- | root@debian9: | + | EDITOR=vim |
- | b3380889eb750298710e956f284f291b786f4382465d247ae58f9b73d2d276ca | + | HOSTNAME=ubuntudocker |
- | root@debian9: | + | |
- | CONTAINER ID IMAGE | + | |
- | b3380889eb75 | + | |
- | bf72bd700870 | + | |
- | d2ddb4f8ca8a | + | |
- | c080793965de | + | |
- | 4f157e179134 | + | |
- | 04b5ab87539a | + | |
</ | </ | ||
- | ====CMD==== | + | < |
+ | root@debian9: | ||
+ | PATH=/ | ||
+ | HOSTNAME=ubuntudocker | ||
+ | EDITOR=vim | ||
+ | HOME=/root | ||
+ | root@debian9: | ||
+ | </ | ||
- | < | + | ====1.11 - Modifier le Nom d' |
- | ... | + | |
- | 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. | + | Pour modifier le nom d'hôte d'un conteneur, utilisez l' |
- | ====Autres Commandes==== | + | < |
+ | root@debian9: | ||
+ | root@ubuntudocker:/# | ||
+ | ubuntudocker | ||
+ | root@ubuntudocker:/# | ||
+ | exit | ||
+ | root@debian9: | ||
+ | </ | ||
- | Le Dockerfile peut aussi contenir les commandes suivantes : | + | ====1.12 - Mapper des Ports d'un Conteneur===== |
- | * **WORKDIR**, | + | Démarrer un conteneur |
- | * Cette commande fixe le répertoire | + | |
- | * **LABEL**, | + | |
- | * Cette commande permet de définir des couples clef/valeur à inclure dans les méta-données décrivant l' | + | |
+ | < | ||
+ | root@debian9: | ||
+ | Unable to find image ' | ||
+ | latest: Pulling from library/ | ||
+ | 27833a3ba0a5: | ||
+ | e83729dd399a: | ||
+ | ebc6a67df66d: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for nginx: | ||
+ | ^Croot@debian9: | ||
+ | </ | ||
- | Lancez maintenant la compilation de l'image : | + | Notez que c'est bloquant. Le fait d' |
< | < | ||
- | root@debian9:~/mongodb# docker | + | ^Croot@debian9:~# docker |
+ | CONTAINER ID IMAGE | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | Consultez la liste de images | + | ====1.13 - Démarrer un Conteneur en mode Détaché==== |
+ | |||
+ | Démarrez maintenant le conteneur | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | REPOSITORY | + | aabb064d4b0ade1f19216b6174631fa32a2053f6aa9d59bd724ea90ce534b004 |
- | < | + | root@debian9: |
- | i2tch/ | + | CONTAINER |
- | nginx latest | + | aabb064d4b0a |
- | centos | + | 4f157e179134 |
- | ubuntu | + | 04b5ab87539a |
- | ubuntu | + | |
- | hello-world | + | |
</ | </ | ||
- | Notez que l' | + | ====1.14 - Accèder aux Services d'un Conteneur de l' |
+ | |||
+ | Installez le navigateur texte **lynx** | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~/mongodb# docker images | + | Lecture des listes de paquets... Fait |
- | REPOSITORY | + | Construction de l' |
- | i2tch/mongodb1 | + | Lecture des informations d' |
- | i2tch/mongodb | + | The following additional packages will be installed: |
- | nginx | + | lynx-common |
- | centos | + | Les NOUVEAUX paquets suivants seront installés : |
- | ubuntu | + | lynx lynx-common |
- | ubuntu | + | 0 mis à jour, 2 nouvellement installés, 0 à enlever et 94 non mis à jour. |
- | hello-world | + | Il est nécessaire de prendre 1 730 ko dans les archives. |
+ | Après cette opération, 5 590 ko d' | ||
+ | Souhaitez-vous continuer ? [O/n] o | ||
+ | Réception de:1 http:// | ||
+ | Réception de:2 http:// | ||
+ | 1 730 ko réceptionnés en 6s (283 ko/s) | ||
+ | Sélection du paquet lynx-common précédemment désélectionné. | ||
+ | (Lecture de la base de données... 113082 fichiers et répertoires déjà installés.) | ||
+ | Préparation du dépaquetage de .../ | ||
+ | Dépaquetage de lynx-common (2.8.9dev11-1) ... | ||
+ | Sélection du paquet lynx précédemment désélectionné. | ||
+ | Préparation du dépaquetage de .../ | ||
+ | Dépaquetage de lynx (2.8.9dev11-1) ... | ||
+ | Traitement des actions différées (« triggers ») pour mime-support (3.60) ... | ||
+ | Traitement des actions différées (« triggers ») pour man-db (2.7.6.1-2) ... | ||
+ | Paramétrage de lynx-common (2.8.9dev11-1) ... | ||
+ | Paramétrage de lynx (2.8.9dev11-1) ... | ||
+ | update-alternatives: | ||
</ | </ | ||
- | Démarrez un conteneur à partir de l' | + | Vérifiez que nginx répond aux requetes |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | bdb4bc0f81de8b5821f20d8609b9640abaaae7b4a7577c42b78d4bd34617d211 | + | |
- | docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \" | + | |
- | root@debian9: | + | If you see this page, the nginx web server is successfully installed |
- | total 16 | + | and working. Further configuration is required. |
- | -rw-r--r-- | + | |
- | -rw-r--r-- 1 root root 3542 avril 9 13:55 Dockerfile | + | For online documentation and support please refer to [1]nginx.org. |
+ | | ||
+ | |||
+ | Thank you for using nginx. | ||
+ | |||
+ | Références | ||
+ | |||
+ | 1. http://nginx.org/ | ||
+ | 2. http:// | ||
</ | </ | ||
- | <WRAP center round important> | + | ====1.15 |
- | **Important** | + | |
- | </ | + | |
- | Recompilez donc l' | + | Arrêtez le conteneur nginx : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | Sending build context to Docker | + | aabb064d4b0a |
- | Step 1/22 : FROM ubuntu: | + | 4f157e179134 |
- | ---> 94e814e2efa8 | + | 04b5ab87539a |
- | Step 2/22 : RUN groupadd -r mongodb && useradd -r -g mongodb mongodb | + | root@debian9:~# docker stop aabb |
- | | + | aabb |
- | | + | root@debian9:~# docker |
- | 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 / | + | CONTAINER ID IMAGE |
- | ---> Using cache | + | aabb064d4b0a |
- | | + | 4f157e179134 |
- | Step 4/22 : ENV GOSU_VERSION 1.11 | + | 04b5ab87539a |
- | | + | |
- | | + | |
- | Step 5/22 : ENV JSYAML_VERSION 3.13.0 | + | |
- | ---> Using cache | + | |
- | | + | |
- | ... | + | |
- | Removing intermediate container a98ae692fe1f | + | |
- | | + | |
- | Step 17/22 : RUN mkdir -p /data/db / | + | |
- | ---> Running in d0f5bee34571 | + | |
- | Removing intermediate container d0f5bee34571 | + | |
- | | + | |
- | Step 18/22 : VOLUME /data/db / | + | |
- | | + | |
- | Removing intermediate container c7626528a9b9 | + | |
- | | + | |
- | Step 19/22 : COPY docker-entrypoint.sh / | + | |
- | ---> eedfd53da0f8 | + | |
- | Step 20/22 : ENTRYPOINT ["docker-entrypoint.sh"] | + | |
- | ---> Running in eff53d0213d1 | + | |
- | Removing intermediate container eff53d0213d1 | + | |
- | | + | |
- | Step 21/22 : EXPOSE 27017 | + | |
- | | + | |
- | Removing intermediate container 5139fcf19d7f | + | |
- | | + | |
- | Step 22/22 : CMD ["mongod" | + | |
- | | + | |
- | Removing intermediate container 458d6f15cdf2 | + | |
- | | + | |
- | Successfully built 12e00099ca8d | + | |
- | root@debian9: | + | |
</ | </ | ||
- | <WRAP center round important> | + | Démarrez |
- | **Important** - Notez ici les lignes **Using cache**. Il est cependant possible | + | |
- | </ | + | |
- | + | ||
- | Consultez la liste des images de nouveau et renommez votre dernière image : | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | REPOSITORY | + | aabb |
- | < | + | root@debian9: |
- | i2tch/ | + | CONTAINER ID |
- | i2tch/ | + | aabb064d4b0a |
- | nginx | + | 4f157e179134 |
- | centos | + | 04b5ab87539a |
- | ubuntu | + | |
- | ubuntu | + | |
- | hello-world | + | |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | REPOSITORY | + | |
- | i2tch/ | + | |
- | i2tch/ | + | |
- | i2tch/mongodb | + | |
- | nginx | + | |
- | centos | + | |
- | ubuntu | + | |
- | ubuntu | + | |
- | hello-world | + | |
</ | </ | ||
- | Lancez | + | ====1.16 - Utiliser des Signaux avec un Conteneur==== |
+ | |||
+ | Utilisez un signal pour tuer le processus du conteneur de nginx : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | e91a055283f4d67cbd91d11bb3faa6f67925893cb18f9cc25023e72e0f7ed85a | + | aabb |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | Utilisez la commande **docker ps** pour visualiser si le processus mongodb est bien démarré | + | Redémarrez un conteneur en cours : |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | CONTAINER ID IMAGE | + | aabb |
- | e91a055283f4 | + | root@debian9: |
- | d2ddb4f8ca8a | + | CONTAINER ID IMAGE |
- | c080793965de | + | aabb064d4b0a |
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9: | ||
+ | aabb | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | Connectez-vous à mongodb à partir de votre machine hôte : | + | ====1.17 |
+ | |||
+ | Supprimez un conteneur en cours d' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | " | + | Error response from daemon: You cannot remove a running container aabb064d4b0ade1f19216b6174631fa32a2053f6aa9d59bd724ea90ce534b004. Stop the container before attempting removal or force remove |
- | " | + | root@debian9:~# docker ps -a |
- | " | + | CONTAINER ID IMAGE |
- | "SecondaryIPv6Addresses": null, | + | aabb064d4b0a |
- | " | + | 4f157e179134 |
- | " | + | 04b5ab87539a |
- | " | + | root@debian9: |
- | " | + | aabb |
- | "IPv6Gateway": "", | + | root@debian9: |
- | " | + | CONTAINER ID IMAGE |
- | " | + | 4f157e179134 |
- | "IPPrefixLen": 16, | + | 04b5ab87539a |
- | " | + | </ |
- | " | + | |
- | " | + | |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | MongoDB shell version v4.0.8 | + | |
- | connecting to: mongodb:// | + | |
- | Implicit session: session { "id" | + | |
- | 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, | + | |
- | The monitoring data will be available on a MongoDB website with a unique URL accessible to you | + | ===1.18 - Utilisation Simple d'un Volume=== |
- | 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() | + | Créez le fichier index.html et placez-le dans le répertoire / |
- | To permanently disable this reminder, run the following command: db.disableFreeMonitoring() | + | |
- | --- | + | |
- | > exit | + | <code> |
- | bye | + | root@debian9: |
- | root@debian9: | + | root@debian9: |
+ | root@debian9: | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | root@debian9: | ||
</ | </ | ||
- | Notez que lors de la compilation de l' | + | Indiquez au conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | REPOSITORY | + | c080793965de8a6a60db212d7e4d96de84b55352c224c054dced75b409e39bf2 |
- | i2tch/mongodb2 | + | root@debian9: |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | root@debian9: |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | i2tch/mongodb1 | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | i2tch/mongodb | + | |
- | < | + | |
- | < | + | |
- | nginx latest | + | |
- | centos | + | |
- | ubuntu | + | |
- | ubuntu | + | |
- | hello-world | + | |
</ | </ | ||
- | =====LAB #5 - Créer un Dockerfile===== | + | <WRAP center round important> |
+ | **Important** | ||
+ | </ | ||
- | ====Création et test du script==== | + | ====1.19 - Télécharger une image sans créer un conteneur==== |
- | Créez | + | Téléchargez l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~/mongodb# cd ~/myDocker | + | Using default tag: latest |
- | root@debian9:~/myDocker# | + | latest: Pulling from library/centos |
+ | 8ba884070f61: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for centos: | ||
</ | </ | ||
- | Créez | + | Vérifiez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~/myDocker# cat myEntrypoint.sh | + | [root@86252a3f00f4 |
- | #!/bin/bash | + | CentOS Linux release 7.6.1810 (Core) |
- | if [ -z " | + | [root@86252a3f00f4 |
- | echo "La variable myVariable doit être renseignée" | + | bind-license-9.9.4-73.el7_6.noarch |
- | return | + | bash-4.2.46-31.el7.x86_64 |
- | fi | + | glibc-common-2.17-260.el7_6.3.x86_64 |
+ | nss-softokn-freebl-3.36.0-5.el7_5.x86_64 | ||
+ | filesystem-3.2-25.el7.x86_64 | ||
+ | glibc-2.17-260.el7_6.3.x86_64 | ||
+ | nspr-4.19.0-1.el7_5.x86_64 | ||
+ | popt-1.13-16.el7.x86_64 | ||
+ | libcom_err-1.42.9-13.el7.x86_64 | ||
+ | libcap-2.22-9.el7.x86_64 | ||
+ | libstdc++-4.8.5-36.el7.x86_64 | ||
+ | info-5.1-5.el7.x86_64 | ||
+ | gawk-4.0.2-4.el7_3.1.x86_64 | ||
+ | libselinux-2.5-14.1.el7.x86_64 | ||
+ | grep-2.20-3.el7.x86_64 | ||
+ | keyutils-libs-1.5.8-3.el7.x86_64 | ||
+ | libverto-0.2.5-4.el7.x86_64 | ||
+ | p11-kit-trust-0.23.5-3.el7.x86_64 | ||
+ | openssl-libs-1.0.2k-16.el7.x86_64 | ||
+ | krb5-libs-1.15.1-37.el7_6.x86_64 | ||
+ | xz-libs-5.2.2-1.el7.x86_64 | ||
+ | libdb-5.3.21-24.el7.x86_64 | ||
+ | libgpg-error-1.12-3.el7.x86_64 | ||
+ | libgcrypt-1.5.3-14.el7.x86_64 | ||
+ | lua-5.1.4-15.el7.x86_64 | ||
+ | libuuid-2.23.2-59.el7.x86_64 | ||
+ | libmount-2.23.2-59.el7.x86_64 | ||
+ | shared-mime-info-1.8-4.el7.x86_64 | ||
+ | gzip-1.5-10.el7.x86_64 | ||
+ | findutils-4.5.11-6.el7.x86_64 | ||
+ | diffutils-3.3-4.el7.x86_64 | ||
+ | expat-2.1.0-10.el7_3.x86_64 | ||
+ | audit-libs-2.8.4-4.el7.x86_64 | ||
+ | pam-1.1.8-22.el7.x86_64 | ||
+ | nss-softokn-3.36.0-5.el7_5.x86_64 | ||
+ | nss-3.36.0-7.1.el7_6.x86_64 | ||
+ | libassuan-2.1.0-3.el7.x86_64 | ||
+ | nss-tools-3.36.0-7.1.el7_6.x86_64 | ||
+ | gobject-introspection-1.56.1-1.el7.x86_64 | ||
+ | --More-- | ||
+ | </ | ||
- | while true; | + | ====1.20 - S' |
- | do | + | |
- | echo $1 \($(date +%H:%M:%S)\); | + | Arretez le conteneur. Démarrez le conteneur puis rattachez-vous au conteneur |
- | sleep "$myVariable"; | + | |
- | done | + | < |
+ | [root@86252a3f00f4 /]# exit | ||
+ | exit | ||
+ | root@debian9:~# docker ps -a | ||
+ | CONTAINER ID IMAGE | ||
+ | 86252a3f00f4 | ||
+ | c080793965de | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9: | ||
+ | 8625 | ||
+ | root@debian9: | ||
+ | [root@86252a3f00f4 /]# ls | ||
+ | anaconda-post.log | ||
+ | [root@86252a3f00f4 /]# | ||
</ | </ | ||
- | Testez ce script | + | ====1.21 - Installer un logiciel dans le conteneur=== |
+ | |||
+ | Réparez les dépôts de CentOS 8 : | ||
< | < | ||
- | root@debian9:~/myDocker# myVariable=3 | + | [root@86252a3f00f4 |
- | salut (20:04:39) | + | [root@86252a3f00f4 /]# sed -i ' |
- | salut (20: | + | [root@86252a3f00f4 |
- | salut (20: | + | |
- | salut (20: | + | |
- | salut (20: | + | |
- | ^C | + | |
- | root@debian9:~/myDocker# | + | |
</ | </ | ||
- | Rendez ce script exécutable | + | Créez le fichier **/ |
< | < | ||
- | root@debian9:~/myDocker# chmod u+x myEntrypoint.sh | + | [root@86252a3f00f4 |
+ | [root@86252a3f00f4 /]# cat / | ||
+ | [mongodb-org-4.2] | ||
+ | name=MongoDB Repository | ||
+ | baseurl=https:// | ||
+ | gpgcheck=1 | ||
+ | enabled=1 | ||
+ | gpgkey=https:// | ||
+ | [root@86252a3f00f4 /]# | ||
</ | </ | ||
- | Créez maintenant le fichier **Dockerfile** dans le répertoire **~/ | + | Installez mongo : |
< | < | ||
- | root@debian9:~/myDocker# vi Dockerfile | + | [root@86252a3f00f4 |
- | root@debian9: | + | |
- | FROM centos: | + | |
- | MAINTAINER i2tch " | + | |
- | COPY myEntrypoint.sh / | + | |
- | ENV myVariable 3 | + | |
- | ENTRYPOINT ["/ | + | |
- | CMD [" | + | |
</ | </ | ||
- | Générez maintenant l' | + | Démarrez mongod |
< | < | ||
- | root@debian9:~/myDocker# docker build -t i2tch/mydocker | + | [root@86252a3f00f4 |
- | Sending build context to Docker daemon | + | [1] 82 |
- | Step 1/6 : FROM centos: | + | [root@86252a3f00f4 |
- | ---> 9f38484d220f | + | forked process: 84 |
- | Step 2/6 : MAINTAINER i2tch "infos@i2tch.eu" | + | child process started successfully, |
- | | + | |
- | Removing intermediate container 02c700ed04da | + | [1]+ Done mongod |
- | | + | [root@86252a3f00f4 |
- | Step 3/6 : COPY myEntrypoint.sh / | + | |
- | ---> 7a3923372768 | + | |
- | Step 4/6 : ENV myVariable 3 | + | |
- | ---> Running in 3288bf6291ad | + | |
- | Removing intermediate container 3288bf6291ad | + | |
- | ---> 3edb630c1511 | + | |
- | Step 5/6 : ENTRYPOINT ["/entrypoint.sh"] | + | |
- | ---> Running in 8dcba2c41520 | + | |
- | Removing intermediate container 8dcba2c41520 | + | |
- | | + | |
- | Step 6/6 : CMD [" | + | |
- | | + | |
- | Removing intermediate container f891fbcfaad0 | + | |
- | | + | |
- | Successfully built 7925ba23abb2 | + | |
- | Successfully tagged i2tch/ | + | |
</ | </ | ||
- | Lancez le conteneur | + | Vérifiez que mongod est démarré |
< | < | ||
- | root@debian9:~/myDocker# docker run -it --name myDocker i2tch/ | + | [root@86252a3f00f4 |
- | mycommand (18:07:12) | + | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND |
- | mycommand (18:07:15) | + | root |
- | mycommand (18:07:18) | + | root 84 1.2 2.2 294692 46716 ? Sl 17:16 0:00 mongod --config / |
- | mycommand (18:07:21) | + | root |
- | ^Cmycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | ^P^Q | + | |
- | root@debian9: | + | |
</ | </ | ||
- | Constatez que le conteneur est toujours en cours de fonctionnement | + | Utilisez |
< | < | ||
- | root@debian9:~/myDocker# docker ps | + | [root@86252a3f00f4 |
- | CONTAINER ID IMAGE | + | MongoDB shell version: 4.2.2 |
- | 140ecfdd80b7 | + | connecting to: test |
- | b3380889eb75 | + | Welcome to the MongoDB shell. |
- | d2ddb4f8ca8a | + | For interactive help, type "help". |
- | c080793965de | + | For more comprehensive documentation, |
- | root@debian9: | + | http://docs.mongodb.org/ |
- | root@debian9:~/myDocker# docker logs myDocker | tail | + | Questions? Try the support group |
- | mycommand (18:08:25) | + | http:// |
- | mycommand (18:08:28) | + | Server has startup warnings: |
- | mycommand (18:08:31) | + | 2019-04-09T17:16:26.951+0000 I CONTROL |
- | mycommand (18:08:34) | + | 2019-04-09T17:16:26.951+0000 I CONTROL |
- | mycommand (18: | + | > |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18:08:52) | + | |
</ | </ | ||
- | Arrêtez le conteneur : | + | Sortez de mongo et du conteneur : |
< | < | ||
- | root@debian9:~/myDocker# docker stop -t 1 myDocker | + | > exit |
- | myDocker | + | bye |
- | root@debian9: | + | [root@86252a3f00f4 |
- | CONTAINER ID IMAGE | + | exit |
- | b3380889eb75 | + | root@debian9: |
- | d2ddb4f8ca8a | + | |
- | c080793965de | + | |
</ | </ | ||
- | Démarrez le conteneur : | + | ====1.22 - Utilisation de la commande docker commit==== |
+ | |||
+ | Créez maintenant une nouvelle image à partir de votre conteneur : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | myDocker | + | CONTAINER ID IMAGE |
- | root@debian9: | + | 86252a3f00f4 |
- | CONTAINER ID IMAGE | + | c080793965de |
- | 140ecfdd80b7 | + | 4f157e179134 |
- | b3380889eb75 | + | 04b5ab87539a |
- | d2ddb4f8ca8a | + | root@debian9: |
- | c080793965de | + | sha256: |
</ | </ | ||
- | Mettez | + | Supprimez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | myDocker | + | 8625 |
- | root@debian9: | + | root@debian9: |
CONTAINER ID IMAGE | CONTAINER ID IMAGE | ||
- | 140ecfdd80b7 | + | c080793965de |
- | b3380889eb75 | + | 4f157e179134 |
- | d2ddb4f8ca8a | + | 04b5ab87539a |
- | c080793965de | + | |
</ | </ | ||
- | Supprimez | + | Utilisez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | myDocker | + | [root@d20fb56a38b0 |
- | root@debian9:~/myDocker# docker ps | + | /usr/bin/ |
- | CONTAINER ID IMAGE | + | / |
- | 140ecfdd80b7 | + | [root@d20fb56a38b0 /]# ps aux |
- | b3380889eb75 | + | USER |
- | d2ddb4f8ca8a | + | root |
- | c080793965de | + | root 15 |
</ | </ | ||
- | Lancez maintenant | + | Editez |
< | < | ||
- | root@debian9:~/myDocker# docker rm -fv myDocker | + | [root@d20fb56a38b0 |
- | myDocker | + | [root@d20fb56a38b0 |
- | root@debian9:~/myDocker# docker run -d --name myDocker i2tch/mydocker | + | . "$i" |
- | 0cf8c8c1bdf4cb05d9852900ecdf171ad9abad0fce29a9f040d5d8436285db65 | + | fi |
- | root@debian9: | + | fi |
- | Up and Running (18:13:33) | + | done |
- | Up and Running (18:13:36) | + | |
- | Up and Running (18:13:39) | + | unset i |
- | Up and Running (18:13:42) | + | unset -f pathmunge |
- | root@debian9: | + | fi |
+ | # vim:ts=4:sw=4 | ||
+ | /usr/ | ||
</ | </ | ||
- | Changez | + | Consultez |
< | < | ||
- | root@debian9:~/myDocker# docker rm -fv myDocker | + | [root@d20fb56a38b0 |
- | myDocker | + | exit |
- | root@debian9: | + | root@debian9: |
- | fbbe3b48c63310e37a3bad5fc962361c39c045a107f47980614efd6b2e8d3981 | + | CONTAINER ID IMAGE |
- | root@debian9: | + | d20fb56a38b0 |
- | mycommand | + | c080793965de |
- | mycommand (18:14:48) | + | 4f157e179134 |
- | mycommand | + | 04b5ab87539a |
- | mycommand | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | mycommand (18: | + | |
- | root@debian9: | + | |
</ | </ | ||
- | ====Bonnes Pratiques liées au Cache==== | + | Utilisez la commande commit pour " |
- | ===Opérations Non-Idempotentes=== | + | < |
+ | root@debian9: | ||
+ | sha256: | ||
+ | </ | ||
- | Créez un répertoire **bestp** ainsi que le fichier Dockerfile suivant | + | Démarrez de nouveau |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | d20f |
- | root@debian9:~# cd bestp | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | root@debian9:~/bestp# cat Dockerfile | + | c080793965de |
- | FROM ubuntu:latest | + | 4f157e179134 |
- | RUN date +%N > /tmp/moment | + | 04b5ab87539a |
- | ENTRYPOINT | + | root@debian9: |
- | CMD ["/tmp/moment" | + | [root@bcec3f27ed58 |
+ | forked process: 16 | ||
+ | child process started successfully, | ||
+ | |||
+ | [1]+ | ||
+ | [root@bcec3f27ed58 /]# ps aux | ||
+ | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND | ||
+ | root | ||
+ | root 16 2.0 2.4 298788 49276 ? Sl | ||
+ | root 39 0.0 0.1 51748 3476 pts/0 R+ | ||
+ | [root@bcec3f27ed58 | ||
</ | </ | ||
- | Le fichier Dokerfile contient une opération non idempotente. | + | ====1.23 - Se connecter au serveur du conteneur de l' |
- | <WRAP center round important> | + | Pour pouvoir se connecter à mongodb depuis la machine hôte, il convient d' |
- | **Important** : Une opération idempotente est une opération qui aboutit systématiquement au même résultat quand elle est lancée dans le même contexte. | + | |
- | </WRAP> | + | |
- | + | ||
- | Compilez l' | + | |
< | < | ||
- | root@debian9:~/bestp# docker build -t testcache . | + | [root@bcec3f27ed58 |
- | Sending build context to Docker daemon | + | [root@bcec3f27ed58 |
- | Step 1/4 : FROM ubuntu: | + | bindIp: 0.0.0.0 |
- | | + | |
- | Step 2/4 : RUN date +%N > /tmp/moment | + | |
- | ---> Running in 6c8c677c1549 | + | |
- | 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:latest | + | |
- | root@debian9: | + | |
</ | </ | ||
- | Exécuter maintenant un premier | + | Sortez du conteneur, re-créez une image, supprimez le conteneur utilisé et relancez de nouveau le conteneur |
< | < | ||
- | root@debian9: | + | [root@bcec3f27ed58 /]# exit |
- | 369009216 | + | exit |
+ | root@debian9: | ||
+ | sha256: | ||
+ | root@debian9: | ||
+ | mongo | ||
+ | root@debian9: | ||
+ | [root@d2ddb4f8ca8a /]# about to fork child process, waiting until server is ready for connections. | ||
+ | forked process: 16 | ||
+ | [root@d2ddb4f8ca8a /]# child process started successfully, | ||
+ | |||
+ | [1]+ Done / | ||
+ | [root@d2ddb4f8ca8a /]# | ||
</ | </ | ||
- | Supprimez maintenant | + | Dans votre machine hôte, configurez |
< | < | ||
- | root@debian9: | + | [root@f5b45072b831 /]# exit |
- | test1 | + | root@debian9: |
- | root@debian9: | + | root@debian9: |
- | Sending build context to Docker daemon | + | root@debian9: |
- | Step 1/4 : FROM ubuntu:latest | + | root@debian9:~# apt-key adv --keyserver hkp:// |
- | ---> 94e814e2efa8 | + | Executing: /tmp/apt-key-gpghome.xMuszKS6JM/ |
- | Step 2/4 : RUN date +%N > /tmp/moment | + | gpg: key 68818C72E52529D4: |
- | ---> Using cache | + | gpg: Total number processed: 1 |
- | ---> 66c3c88c57bb | + | gpg: |
- | Step 3/4 : ENTRYPOINT ["more"] | + | root@debian9:~# |
- | ---> Using cache | + | root@debian9: |
- | ---> 81cb68241ec9 | + | deb http:// |
- | Step 4/4 : CMD ["/tmp/moment"] | + | root@debian9:~# |
- | ---> Using cache | + | root@debian9: |
- | ---> c55a42a18572 | + | |
- | Successfully built c55a42a18572 | + | |
- | Successfully tagged testcache:latest | + | |
- | root@debian9: | + | |
</ | </ | ||
- | Lancez un conteneur à partir | + | Cette fois, installez uniquement le client |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 369009216 | + | Lecture des listes de paquets... Fait |
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | Les NOUVEAUX paquets suivants seront installés : | ||
+ | mongodb-org-shell | ||
+ | 0 mis à jour, 1 nouvellement installés, 0 à enlever et 95 non mis à jour. | ||
+ | Il est nécessaire de prendre 9 809 ko dans les archives. | ||
+ | Après cette opération, 39,8 Mo d' | ||
+ | Réception de:1 http:// | ||
+ | 9 809 ko réceptionnés en 7s (1 245 ko/s) | ||
+ | Sélection du paquet mongodb-org-shell précédemment désélectionné. | ||
+ | (Lecture de la base de données... 91513 fichiers et répertoires déjà installés.) | ||
+ | Préparation du dépaquetage de .../ | ||
+ | Dépaquetage de mongodb-org-shell (4.0.8) ... | ||
+ | Paramétrage de mongodb-org-shell (4.0.8) ... | ||
+ | Traitement des actions différées (« triggers ») pour man-db (2.7.6.1-2) ... | ||
</ | </ | ||
- | <WRAP center round important> | + | Notez qu'à ce stade le conteneur |
- | **Important** - Notez que les deux sorties des conteneurs sont identiques malgré | + | |
- | </ | + | |
- | + | ||
- | Pour contourner ce problème, | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~/bestp# cat Dockerfile | + | " |
- | FROM ubuntu:latest | + | " |
- | RUN date +%N > /tmp/moment \ | + | " |
- | && | + | "SecondaryIPv6Addresses": null, |
- | ENTRYPOINT ["more"] | + | "GlobalIPv6Address": "", |
- | CMD ["/tmp/moment"] | + | "GlobalIPv6PrefixLen": 0, |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
</ | </ | ||
- | Supprimez maintenant | + | Démarrez donc le conteneur et cherchez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | test1 | + | mongo |
- | root@debian9: | + | root@debian9: |
- | Sending build context to Docker daemon | + | " |
- | Step 1/4 : FROM ubuntu:latest | + | " |
- | ---> 94e814e2efa8 | + | " |
- | Step 2/4 : RUN date +%N > / | + | " |
- | ---> Running in 3d2a5cee6ac8 | + | " |
- | Removing intermediate container 3d2a5cee6ac8 | + | " |
- | ---> 75d0498a9676 | + | " |
- | Step 3/4 : ENTRYPOINT ["more"] | + | " |
- | ---> Running in 88c0cec68659 | + | " |
- | Removing intermediate container 88c0cec68659 | + | " |
- | ---> 2aee524c8da4 | + | " |
- | Step 4/4 : CMD ["/tmp/moment"] | + | " |
- | ---> Running in 82d2162bb701 | + | " |
- | Removing intermediate container 82d2162bb701 | + | " |
- | | + | " |
- | Successfully built a54c4af89994 | + | |
- | Successfully tagged testcache:latest | + | |
</ | </ | ||
- | Lancez un conteneur | + | Connectez-vous maintenant à votre mongodb |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 746997174 | + | MongoDB shell version v4.0.8 |
+ | connecting to: mongodb:// | ||
+ | WARNING: No implicit session: Logical Sessions are only supported on server versions 3.6 and greater. | ||
+ | Implicit session: dummy session | ||
+ | MongoDB server version: 4.2.2 | ||
+ | WARNING: shell and server versions do not match | ||
+ | Welcome to the MongoDB shell. | ||
+ | For interactive help, type " | ||
+ | For more comprehensive documentation, | ||
+ | http:// | ||
+ | Questions? Try the support group | ||
+ | http:// | ||
+ | Server has startup warnings: | ||
+ | 2019-04-09T17: | ||
+ | 2019-04-09T17: | ||
+ | > | ||
</ | </ | ||
----- | ----- | ||
- | < | + | |
- | <div align=" | + | Copyright © 2022 Hugh Norris. |
- | Copyright © 2020 Hugh NORRIS | + | |
- | </ | + | |
- | </ | + |