Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
elearning:workbooks:centos:6:sec:l110 [2021/02/28 14:19] – created admin | elearning:workbooks:centos:6:sec:l110 [2021/02/28 16:45] (Version actuelle) – admin | ||
---|---|---|---|
Ligne 5: | Ligne 5: | ||
Dernière mise-à-jour : ~~LASTMOD~~ | Dernière mise-à-jour : ~~LASTMOD~~ | ||
- | ======LRF410 - La Virtualisation par Isolation====== | + | ======LRF410 - Démarrer avec Docker====== |
=====Contenu du Module===== | =====Contenu du Module===== | ||
- | * **LRF410 - La Virtualisation par Isolation** | + | * **LRF410 - Démarrer avec Docker** |
* Contenu du Module | * Contenu du Module | ||
- | * Présentation de la Virtualisation par Isolation | + | * Présentation de Docker |
- | * Historique | + | * LAB #1 - Travailler avec Docker |
- | | + | * 1.1 - Installer docker |
- | * Présentation des CGroups | + | * 1.2 - Démarrer un Conteneur |
- | | + | * 1.3 - Consulter la Liste des Conteneurs et Images |
- | * 1.1 - Limitation de la Mémoire | + | * 1.4 - Rechercher une Image dans un Dépôt |
- | * 1.2 - Le Paquet cgroup-tools | + | * 1.5 - Supprimer un Conteneur d'une Image |
- | * La commande cgcreate | + | * 1.6 - Créer une Image à partir d'un Conteneur Modifié |
- | * La Commande cgexec | + | * 1.7 - Supprimer une Image |
- | * La Commande cgdelete | + | * 1.8 - Créer un Conteneur |
- | * Le Fichier / | + | * 1.9 - Exécuter une Commande dans un Conteneur |
- | * Présentation de Linux Containers | + | * 1.10 - Injecter des Variables |
- | * LAB #2 - Travailler | + | * 1.11 - Modifier le Nom d' |
- | * 2.1 - Installation | + | * 1.12 - Mapper des Ports d'un Conteneur |
- | * 2.2 - Création | + | * 1.13 - Démarrer un Conteneur en mode Détaché |
- | * 2.3 - Démarrage | + | * 1.14 - Accéder aux Services d'un Conteneur de l' |
- | * 2.4 - S'attacher à un Conteneur | + | * 1.15 - Arrêter et Démarrer un Conteneur |
- | * 2.5 - Commandes LXC de Base | + | * 1.16 - Utiliser des Signaux avec un Conteneur |
- | * La Commande lxc-console | + | * 1.17 - Forcer la Suppression |
- | * La Commande lxc-stop | + | * 1.18 - Utilisation Simple |
- | * La Commande lxc-execute | + | * 1.19 - Télécharger une image sans créer un conteneur |
- | * La Commande lxc-info | + | * 1.20 - S'attacher à un conteneur en cours d' |
- | * La Commande lxc-freeze | + | * 1.21 - Installer un logiciel dans le conteneur |
- | * La Commande lxc-unfreeze | + | * 1.22 - Utilisation de la commande docker commit |
- | * Autres commandes | + | * 1.23 - Se connecter au serveur du conteneur de l' |
- | * 2.6 - Création | + | |
- | * User Namespaces | + | |
- | * Création | + | |
- | * Création du Mappage | + | |
- | * Création du Conteneur | + | |
- | * Contrôle du Mappage | + | |
- | * 2.7 - Création d' | + | |
- | * La Commande lxc-copy | + | |
- | * 2.8 - Sauvegarde des Conteneurs | + | |
- | * La Commande lxc-snapshot | + | |
- | =====Présentation de la Virtualisation par Isolation===== | + | =====Présentation de Docker===== |
- | Un isolateur | + | Docker |
- | ====Historique==== | + | Une **image** est un paquet exécutable contenant tout ce qu'il est necessaire afin d' |
- | * **1979** - [[https:// | + | * le code |
- | * **2000** - [[https:// | + | * un runtime |
- | * **2004** - [[https:// | + | * des bibliothèques, |
- | * **2005** - [[https:// | + | * des variables d'environnement |
- | * **2008** - [[https:// | + | * des fichiers de configuration |
- | * **2013** - [[https:// | + | |
- | * **2014** - [[https:// | + | |
- | =====Présentation | + | Un **conteneur** est une instance de l' |
- | Les espaces | + | 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 |
- | =====Présentation des CGroups===== | + | 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:// |
- | Les Groupes de Contrôles (Control Groups) aussi appelés **CGroups**, | + | =====LAB #1 - Travailler avec Docker===== |
- | Les CGroups sont organisés de manière hiérarchique, | + | ====1.1 - Installer docker==== |
- | Ces hiérarchies multiples et séparés sont necéssaires parce que chaque hiérarchie est attaché à un ou plusieurs sous-système(s) aussi appelés des **Contrôleurs de Ressources** ou simplement des **Contrôleurs**. Les contrôleurs disponibles sont : | + | Installer Docker-CE sur **votre** ordinateur |
- | * **blkio** - utilisé pour établir des limites sur l' | + | ==Mac== |
- | * **cpu** - utilisé pour fournir aux tâches des groupes de contrôle accès au CPU grâce au planificateur, | + | |
- | * **cpuacct** - utilisé pour produire des rapports automatiques sur les ressources CPU utilisées par les tâches dans un groupe de contrôle, | + | |
- | * **cpuset** - utilisé pour assigner des CPU individuels sur un système multicœur et des nœuds de mémoire à des tâches dans un groupe de contrôle, | + | |
- | * **devices** - utilisé pour autoriser ou pour refuser l' | + | |
- | * **freezer** - utilisé pour suspendre ou pour réactiver les tâches dans un groupe de contrôle, | + | |
- | * **memory** - utilisé pour établir les limites d' | + | |
- | * **net_cls** - utilisé pour repérer les paquets réseau avec un identifiant de classe (classid) afin de permettre au contrôleur de trafic Linux, **tc**, d' | + | |
- | * **perf_event** - utilisé pour permettre le monitoring des CGroups avec l' | + | |
- | * **hugetlb** - utilisé pour limiter des ressources sur des pages de mémoire virtuelle de grande taille. | + | |
- | Les hiérarchies ont des points de montage dans le répertoire | + | * Voir le lien **[[https://docs.docker.com/docker-for-mac/ |
- | < | + | ==Linux== |
- | trainee@debian9: | + | |
- | Mot de passe : fenestros | + | |
- | root@debian9: | + | |
- | total 0 | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 blkio | + | |
- | lrwxrwxrwx 1 root root 11 mai 26 08:52 cpu -> cpu, | + | |
- | lrwxrwxrwx 1 root root 11 mai 26 08:52 cpuacct -> cpu, | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 cpu, | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 cpuset | + | |
- | dr-xr-xr-x 5 root root 0 mai 26 08:52 devices | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 freezer | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 memory | + | |
- | lrwxrwxrwx 1 root root 16 mai 26 08:52 net_cls -> net_cls, | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 net_cls, | + | |
- | lrwxrwxrwx 1 root root 16 mai 26 08:52 net_prio -> net_cls, | + | |
- | dr-xr-xr-x 2 root root 0 mai 26 08:52 perf_event | + | |
- | dr-xr-xr-x 5 root root 0 mai 26 08:52 pids | + | |
- | dr-xr-xr-x 5 root root 0 mai 26 08:52 systemd | + | |
- | </ | + | |
- | **Systemd** organise les processus dans chaque CGroup. Par exemple tous les processus démarrés par le serveur Apache se trouveront dans le même CGroup, y compris les scripts CGI. Ceci implique que la gestion des ressources en utilisant des hiérarchies est couplé avec l' | + | |
+ | * Debian - voir le lien **[[https:// | ||
+ | * CentOS - voir le lien **[[https:// | ||
+ | * Fedora - voir le lien **[[https:// | ||
- | En haut de l' | + | ==Windows 7, 8== |
- | * le **system.slice** - l' | + | * Téléchargez Docker Toolbox à partir de cette page **[[https:// |
- | * le **user.slice** - l'emplacement des sessions des utilisateurs, | + | * Fermez toutes les machines virtuelles ainsi que VirtualBox, |
- | * le **machine.slice** - l' | + | * Installez |
+ | * Exécutez Docker Toolbox et laissez | ||
+ | * Ouvrez VirtualBox. Vous verrez une machine virtuelle Default, | ||
+ | | ||
- | En dessous des tranches peuvent se trouver : | + | ==Windows 10== |
- | * des **scopes** - des processus crées par **fork**, | + | * Voir le lien **[[https:// |
- | * des **services** | + | |
- | Les slices peuvent être visualisés avec la commande suivante | + | |
+ | ====1.2 - Démarrer un Conteneur==== | ||
+ | |||
+ | Démarrez un conteneur de l' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | UNIT | + | Unable to find image 'hello-world: |
- | -.slice | + | latest: Pulling from library/ |
- | system-getty.slice loaded active active system-getty.slice | + | 1b930d010525: |
- | system.slice | + | Digest: sha256: |
- | user-1000.slice | + | Status: Downloaded newer image for hello-world: |
- | user-112.slice | + | |
- | user.slice | + | |
- | LOAD = Reflects whether the unit definition was properly loaded. | + | Hello from Docker! |
- | ACTIVE = The high-level unit activation state, i.e. generalization of SUB. | + | This message shows that your installation appears to be working correctly. |
- | SUB = The low-level unit activation state, values depend on unit type. | + | |
- | 6 loaded units listed. Pass --all to see loaded but inactive units, too. | + | To generate this message, Docker took the following steps: |
- | To show all installed unit files use ' | + | 1. The Docker client contacted the Docker daemon. |
- | </ | + | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. |
+ | (amd64) | ||
+ | 3. The Docker daemon created a new container from that image which runs the | ||
+ | executable that produces the output you are currently reading. | ||
+ | 4. The Docker daemon streamed that output | ||
+ | to your terminal. | ||
+ | |||
+ | To try something more ambitious, you can run an Ubuntu container with: | ||
+ | $ docker run -it ubuntu bash | ||
- | L' | + | Share images, automate workflows, and more with a free Docker ID: |
+ | | ||
- | < | + | For more examples and ideas, visit: |
- | root@debian9:~# systemd-cgls | + | https://docs.docker.com/get-started/ |
- | Control group /: | + | |
- | -.slice | + | |
- | ├─user.slice | + | |
- | │ ├─user-112.slice | + | |
- | │ │ ├─user@112.service | + | |
- | │ │ │ ├─dbus.service | + | |
- | │ │ │ │ └─539 | + | |
- | │ │ │ ├─init.scope | + | |
- | │ │ │ │ ├─527 / | + | |
- | │ │ │ │ └─528 (sd-pam) | + | |
- | │ │ │ └─gvfs-daemon.service | + | |
- | │ │ │ | + | |
- | │ │ └─session-c1.scope | + | |
- | │ │ | + | |
- | │ │ | + | |
- | │ │ | + | |
- | │ │ | + | |
- | │ │ | + | |
- | │ └─user-1000.slice | + | |
- | │ | + | |
- | │ │ ├─668 sshd: trainee [priv] | + | |
- | │ │ ├─679 sshd: trainee@pts/ | + | |
- | │ │ ├─680 -bash | + | |
- | │ │ ├─689 su - | + | |
- | │ │ ├─690 -su | + | |
- | │ │ ├─708 systemd-cgls | + | |
- | │ │ └─709 systemd-cgls | + | |
- | │ | + | |
- | │ | + | |
- | │ | + | |
- | │ | + | |
- | ├─init.scope | + | |
- | │ └─1 / | + | |
- | └─system.slice | + | |
- | ├─lightdm.service | + | |
- | │ ├─410 / | + | |
- | │ ├─425 / | + | |
- | │ └─588 lightdm --session-child 14 21 | + | |
- | ├─anacron.service | + | |
- | lines 1-39 | + | |
</ | </ | ||
- | |||
- | En utilisant Systemd, plusieurs ressources peuvent être limitées : | ||
- | |||
- | * **CPUShares** - par défaut 1024, | ||
- | * **MemoryLimit** - limite exprimée en Mo ou en Go. Pas de valeur par défaut, | ||
- | * **BlockIOWeight** - valeur entre 10 et 1000. Pas de valeur par défaut, | ||
- | * **StartupCPUShares** - comme CPUShares mais uniquement appliqué pendant le démarrage, | ||
- | * **StartupBlockIOWeight** - comme BlockIOWeight mais uniquement appliqué pendant le démarrage, | ||
- | * **CPUQuota** - utilisé pour limiter le temps CPU, même quand le système ne fait rien. | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** | + | **Important** |
</ | </ | ||
- | ====LAB #1 - Travailler avec les CGroups==== | + | Démarrez un conteneur |
- | + | ||
- | ===1.1 - Limitation | + | |
- | + | ||
- | Pour travailler avec les CGroups dans Debian 9, il convient d'installer les outils nécessaires | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | 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=" | ||
</ | </ | ||
- | Commencez ensuite par créer le script | + | <WRAP center round important> |
+ | **Important** - Notez que dans ce cas le conteneur est lancé avec comme argument **bash** qui lancera /bin/bash dans le conteneur. | ||
+ | </ | ||
+ | |||
+ | Consulter la liste des paquets installés dans le conteneur ubuntu | ||
< | < | ||
- | root@debian9:~# vi hello-world.sh | + | root@835001339e79:/# dpkg -l |
- | root@debian9:~# cat hello-world.sh | + | Desired=Unknown/ |
- | #!/bin/bash | + | | Status=Not/ |
- | while [ 1 ]; do | + | |/ Err? |
- | echo "hello world" | + | ||/ Name |
- | sleep 60 | + | +++-====================================-=======================-=======================-============================================================================= |
- | done | + | 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 2.2.4-1ubuntu1.2 amd64 GNU privacy guard - signature verification tool | ||
+ | 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 | ||
+ | ii ubuntu-keyring | ||
+ | ii util-linux | ||
+ | ii zlib1g: | ||
+ | root@835001339e79:/# | ||
+ | exit | ||
+ | root@debian9: | ||
</ | </ | ||
- | Rendez le script exécutable et testez-le | + | Les options de la commande docker run peuvent être visualisées avec la commande |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | |
- | hello world | + | |
- | hello world | + | |
- | ^C | + | |
- | </ | + | |
- | Créez maintenant un CGroup dans le sous-système **memory** appelé **helloworld** | + | Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] |
- | < | + | Run a command in a new container |
- | root@debian9:~# mkdir /sys/fs/cgroup/ | + | |
+ | Options: | ||
+ | --add-host list Add a custom host-to-IP mapping (host:ip) | ||
+ | -a, --attach list Attach to STDIN, STDOUT or STDERR | ||
+ | --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 | ||
+ | --memory-reservation bytes | ||
+ | --memory-swap bytes Swap limit equal to memory plus 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 | ||
</ | </ | ||
- | Par défaut, ce CGroup héritera de l' | + | ====1.3 - Consulter la Liste des Conteneurs et Images==== |
+ | |||
+ | Pour consulter tous les conteneurs, utilisez la commande **docker ps** avec l' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | 39997440 | + | 3a3f9bda6cbd |
+ | 26ef17bd115d | ||
</ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** - Notez que les 40 000 000 demandés sont devenus 39 997 440 ce qui correspond à un nombre entier de pages mémoire du noyau de 4Ko. ( 39 997 440 / 4096 = 9 765 ). | + | **Important** - Notez que chaque conteneur peut être référencé par son **CONTAINER ID** ou par son **NAME**. |
</ | </ | ||
- | Lancez maintenant le script | + | Pour consulter la liste des images, utilisez la commande |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [1] 1012 | + | REPOSITORY |
- | root@debian9: | + | ubuntu |
- | + | hello-world | |
- | root@debian9: | + | |
- | root 1012 0.0 0.1 11172 2868 pts/0 S 10:24 0:00 /bin/bash ./ | + | |
- | root 1015 0.0 0.0 12784 968 pts/0 S+ | + | |
</ | </ | ||
- | Notez l' | + | <WRAP center round important> |
+ | **Important** - Notez que chaque image est référencée | ||
+ | </ | ||
- | < | + | ====1.4 - Rechercher une Image dans un Dépôt==== |
- | root@debian9: | + | |
- | CGROUP | + | |
- | 6: | + | |
- | </ | + | |
- | Insérer le PID de notre script | + | Pour rechercher une image docker |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | NAME DESCRIPTION | ||
+ | centos | ||
+ | ansible/centos7-ansible | ||
+ | jdeathe/centos-ssh | ||
+ | consol/centos-xfce-vnc | ||
+ | imagine10255/centos6-lnmp-php56 | ||
+ | centos/ | ||
+ | tutum/ | ||
+ | gluster/ | ||
+ | openshift/ | ||
+ | centos/ | ||
+ | centos/ | ||
+ | kinogmt/ | ||
+ | centos/ | ||
+ | centos/ | ||
+ | openshift/ | ||
+ | pivotaldata/ | ||
+ | openshift/wildfly-101-centos7 | ||
</ | </ | ||
- | Notez maintenant | + | <WRAP center round important> |
+ | **Important** - Notez que chaque image est référencée par la colonne NAME. Le NAME est sous le format **repository/ | ||
+ | </ | ||
- | < | + | ====1.5 - Supprimer un Conteneur d'une Image==== |
- | root@debian9: | + | |
- | CGROUP | + | |
- | 6: | + | |
- | </ | + | |
- | Constatez ensuite l'occupation mémoire réelle | + | Pour supprimer un conteneur d'une image, il convient d' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 319488 | + | CONTAINER ID IMAGE |
+ | 3a3f9bda6cbd | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | wizardly_buck | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Tuez le script | + | <WRAP center round important> |
+ | **Important** - Notez que dans le cas de l' | ||
+ | </ | ||
+ | |||
+ | ====1.6 -Créer une Image à partir d'un Conteneur Modifié=== | ||
+ | |||
+ | Modifier un conteneur d'une image : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~# ps aux | grep hello-world | + | root@54b0dae2f3a9:/# ls |
- | root | + | bin boot dev etc home lib lib64 media mnt opt proc |
- | [1]+ Complété | + | root@54b0dae2f3a9:/# rm -rf /home |
+ | 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: | ||
</ | </ | ||
- | Créez un second CGroup beaucoup plus restrictif | + | <WRAP center round important> |
+ | **Important** - Notez ici la suppression du répertoire **home** dans le conteneur **54b0dae2f3a9**. | ||
+ | </ | ||
+ | |||
+ | Consultez la différence entre le conteneur et l' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | root@debian9: | + | 54b0dae2f3a9 |
- | 4096 | + | 26ef17bd115d |
+ | root@debian9: | ||
+ | C /root | ||
+ | A /root/.bash_history | ||
+ | D /home | ||
</ | </ | ||
- | Relancez le script | + | <WRAP center round important> |
+ | **Important** - La sortie de la commande **docker diff** comporte des lettres dont les significations sont les suivantes | ||
+ | </ | ||
- | < | + | Créez un autre conteneur à partir de l' |
- | root@debian9:~# ./ | + | |
- | [1] 1042 | + | |
- | root@debian9: | + | |
- | root@debian9: | + | < |
+ | root@debian9: | ||
+ | root@92f0d4bb7967: | ||
+ | bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv | ||
+ | root@92f0d4bb7967: | ||
+ | exit | ||
+ | root@debian9: | ||
</ | </ | ||
- | Attendez la prochaine sortie de **hello world** sur le canal standard puis constatez que le script s'arrête : | + | <WRAP center round important> |
+ | **Important** - Dans ce nouveau conteneur, | ||
+ | </ | ||
- | < | + | Créez maintenant l' |
- | root@debian9:~# hello world | + | |
- | [1]+ Processus arrêté | + | < |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | root@debian9: | ||
+ | sha256: | ||
+ | root@debian9: | ||
+ | REPOSITORY | ||
+ | ubuntu_1 | ||
+ | ubuntu | ||
+ | hello-world | ||
</ | </ | ||
- | Consultez en suite la fin du fichier | + | ====1.7 - Supprimer une Image==== |
+ | |||
+ | Créez maintenant un conteneur à partir de la nouvelle image **ubuntu_1** : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775169] | + | root@904215fb79b4:/# ls |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775171] | + | bin boot dev etc lib lib64 media mnt opt proc root run sbin srv sys tmp usr var |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775175] | + | root@904215fb79b4:/# exit |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775176] Task in / | + | exit |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775180] memory: usage 4kB, limit 4kB, failcnt 17 | + | root@debian9:~# |
- | Jul 28 10: | + | |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775181] kmem: usage 0kB, limit 9007199254740988kB, | + | |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775181] Memory cgroup stats for / | + | |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775188] [ pid ] | + | |
- | Jul 28 10:39:26 debian9 kernel: [ 1501.775219] [ 1042] | + | |
</ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** - Notez la trace **Task in / | + | **Important** - Notez l' |
</ | </ | ||
- | ===1.2 - Le Paquet cgroup-tools=== | + | Essayez de supprimer l' |
- | Le paquet **cgroup-tools** installe des commandes dites //de facilité// dont : | + | < |
+ | root@debian9: | ||
+ | Error response from daemon: conflict: unable to remove repository reference " | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 904215fb79b4 | ||
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
+ | </ | ||
- | ==La commande cgcreate== | + | <WRAP center round important> |
+ | **Important** - Notez qu'il n'est pas possible de supprimer l' | ||
+ | </ | ||
- | Cette commande permet la création d'un CGroup | + | Supprimez donc le conteneur **priceless_swirles** ainsi que l'image **ubuntu_1** |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | priceless_swirles |
- | total 0 | + | root@debian9: |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 cgroup.clone_children | + | CONTAINER ID IMAGE |
- | --w--w--w- 1 root root 0 juil. 28 11:09 cgroup.event_control | + | 92f0d4bb7967 |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 cgroup.procs | + | 54b0dae2f3a9 |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.failcnt | + | 26ef17bd115d |
- | --w------- 1 root root 0 juil. 28 11:09 memory.force_empty | + | root@debian9:~# docker rmi ubuntu_1 |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.failcnt | + | Untagged: ubuntu_1:latest |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.limit_in_bytes | + | Deleted: sha256:2ba8e0ec5e38332c8ab15c4b33fd140a9c74d72231d05a6965c40a39fbb44584 |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.max_usage_in_bytes | + | Deleted: sha256:308e9761a8fc84661e46eff564b0bbca12b458e71bdf77bf4abbb59b21efdbbe |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.slabinfo | + | root@debian9:~# docker images |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.tcp.failcnt | + | REPOSITORY |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.tcp.limit_in_bytes | + | ubuntu |
- | -rw-r--r-- | + | hello-world |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.tcp.usage_in_bytes | + | |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.kmem.usage_in_bytes | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.limit_in_bytes | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.max_usage_in_bytes | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.move_charge_at_immigrate | + | |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.numa_stat | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.oom_control | + | |
- | ---------- 1 root root 0 juil. 28 11:09 memory.pressure_level | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.soft_limit_in_bytes | + | |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.stat | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.swappiness | + | |
- | -r--r--r-- 1 root root 0 juil. 28 11:09 memory.usage_in_bytes | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 memory.use_hierarchy | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 notify_on_release | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 11:09 tasks | + | |
</ | </ | ||
- | Il n' | + | Pour pouvoir supprimer tous les conteneurs, listez-les par leur **Container ID** : |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | 92f0d4bb7967 | ||
+ | 54b0dae2f3a9 | ||
+ | 26ef17bd115d | ||
</ | </ | ||
- | ==La Commande cgexec== | + | Supprimer toutes les conteneurs |
- | + | ||
- | Cette commande permet d' | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | [2] 1860 | + | 92f0d4bb7967 |
- | root@debian9: | + | 54b0dae2f3a9 |
- | + | 26ef17bd115d | |
- | root@debian9: | + | root@debian9: |
+ | root@debian9: | ||
</ | </ | ||
- | == La Commande cgdelete== | + | Pour supprimer |
- | + | ||
- | Une fois le script terminé, cette commande permet de supprimer | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root | + | root@d123b0112fc2:/# |
- | root | + | bin boot dev etc home lib lib64 media mnt opt proc |
- | root@debian9:~# kill 1073 | + | root@d123b0112fc2:/# exit |
- | root@debian9: | + | exit |
- | root 1078 0.0 0.0 12784 920 pts/0 S+ | + | root@debian9: |
- | [1]+ Complété | + | root@debian9: |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | ls: impossible d' | + | |
</ | </ | ||
- | ==Le Fichier / | + | ====1.8 - Créer un Conteneur avec un Nom Spécifique==== |
- | Afin de les rendre persistants, | + | Créez maintenant un conteneur avec un nom spécifique |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | root@04b5ab87539a: |
- | group helloworld2 { | + | bin boot dev |
- | cpu { | + | root@04b5ab87539a: |
- | cpu.shares = 100; | + | exit |
- | } | + | root@debian9: |
- | memory { | + | CONTAINER ID IMAGE |
- | memory.limit_in_bytes = 40000; | + | 04b5ab87539a |
- | } | + | |
- | } | + | |
</ | </ | ||
- | <WRAP center round important> | + | Pour obtenir |
- | **Important** - Notez la création de **deux** limitations, | + | |
- | </ | + | |
- | + | ||
- | Créez donc les deux CGroups concernés | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~# ls -l /sys/ | + | [ |
- | total 0 | + | { |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 cgroup.clone_children | + | " |
- | --w--w--w- 1 root root 0 juil. 28 12:47 cgroup.event_control | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 cgroup.procs | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.failcnt | + | " |
- | --w------- 1 root root 0 juil. 28 12:47 memory.force_empty | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.failcnt | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.limit_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.max_usage_in_bytes | + | " |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.slabinfo | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.tcp.failcnt | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.tcp.limit_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.tcp.max_usage_in_bytes | + | " |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.tcp.usage_in_bytes | + | " |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.kmem.usage_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.limit_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.max_usage_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.move_charge_at_immigrate | + | }, |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.numa_stat | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.oom_control | + | " |
- | ---------- 1 root root 0 juil. 28 12:47 memory.pressure_level | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.soft_limit_in_bytes | + | " |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.stat | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.swappiness | + | " |
- | -r--r--r-- 1 root root 0 juil. 28 12:47 memory.usage_in_bytes | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 memory.use_hierarchy | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 notify_on_release | + | " |
- | -rw-r--r-- 1 root root 0 juil. 28 12:47 tasks | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | 0 | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | ], | ||
+ | " | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | "/ | ||
+ | ] | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | "/ | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | ] | ||
</ | </ | ||
- | < | + | ====1.9 - Exécuter une Commande dans un Conteneur==== |
- | root@debian9: | + | |
- | root@debian9: | + | |
- | total 0 | + | |
- | -rw-r--r-- | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 cgroup.procs | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.stat | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_all | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_percpu | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_percpu_sys | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_percpu_user | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_sys | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpuacct.usage_user | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 cpu.cfs_period_us | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 cpu.cfs_quota_us | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 cpu.shares | + | |
- | -r--r--r-- 1 root root 0 juil. 28 12:48 cpu.stat | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 notify_on_release | + | |
- | -rw-r--r-- 1 root root 0 juil. 28 12:48 tasks | + | |
- | </ | + | |
- | Appliquez le contenu du fichier **/ | + | Pour exécuter une commande spécifique dans un conteneur, passez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~# cat /sys/fs/cgroup/memory/helloworld2/memory.limit_in_bytes | + | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/ |
- | 36864 | + | HOSTNAME=77bb110031aa |
- | root@debian9: | + | HOME=/root |
- | 100 | + | root@debian9: |
</ | </ | ||
- | =====Présentation de Linux Containers===== | + | ====1.10 - Injecter des Variables d' |
- | ====LAB #2 - Travailler avec LXC==== | + | Pour injecter une ou des variables d'environnement |
- | + | ||
- | ===2.1 - Installation=== | + | |
- | + | ||
- | Les outils indispensables à l'utilisation des Linux Containers sous Debian sont inclus | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | root@debian9: |
+ | EDITOR=vim | ||
+ | HOSTNAME=ubuntudocker | ||
</ | </ | ||
- | |||
- | L' | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | config hooks | + | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/ |
- | root@debian9:~# ls /usr/share/lxc/config | + | HOSTNAME=ubuntudocker |
- | alpine.common.conf | + | EDITOR=vim |
- | alpine.userns.conf | + | HOME=/root |
- | archlinux.common.conf | + | root@debian9: |
- | archlinux.userns.conf | + | |
- | centos.common.conf | + | |
- | root@debian9: | + | |
- | lxc-alpine | + | |
- | lxc-altlinux | + | |
</ | </ | ||
- | ===2.2 - Création | + | ====1.11 - Modifier le Nom d' |
- | Créez | + | Pour modifier le nom d' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | chmod: impossible d' | + | root@ubuntudocker:/# hostname |
- | setting | + | ubuntudocker |
- | Failed to change | + | root@ubuntudocker:/# |
+ | exit | ||
+ | root@debian9: | ||
</ | </ | ||
- | <WRAP center round important> | + | ====1.12 |
- | **Important** | + | |
- | </ | + | |
- | Le **backingstore** (// méthode | + | Démarrer un conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | lxc-bb | + | Unable to find image ' |
- | + | latest: Pulling from library/nginx | |
- | root@debian9:~# ls / | + | 27833a3ba0a5: |
- | config rootfs | + | e83729dd399a: |
- | + | ebc6a67df66d: | |
- | root@debian9: | + | Digest: sha256: |
- | bin dev etc home lib lib64 mnt proc root sbin selinux | + | Status: Downloaded newer image for nginx: |
+ | ^Croot@debian9: | ||
</ | </ | ||
- | Il est à noter que LXC peut également utiliser des backingstores de type : | + | Notez que c'est bloquant. Le fait d'avoir utiliser ^C a interrompu |
- | + | ||
- | * ZFS | + | |
- | * Brtfs | + | |
- | * LVM | + | |
- | * Loop | + | |
- | * rbd (CephFS) | + | |
- | + | ||
- | ===2.3 - Démarrage | + | |
- | + | ||
- | Pour démarrer | + | |
< | < | ||
- | root@debian9: | + | ^Croot@debian9: |
+ | CONTAINER ID IMAGE | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | ===2.4 - S' | + | ====1.13 - Démarrer |
- | Pour s' | + | Démarrez maintenant le conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
+ | aabb064d4b0ade1f19216b6174631fa32a2053f6aa9d59bd724ea90ce534b004 | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | </ | ||
+ | ====1.14 - Accèder aux Services d'un Conteneur de l' | ||
- | BusyBox v1.22.1 (Debian 1: | + | Installez |
- | Enter ' | + | |
- | + | ||
- | ~ # passwd | + | |
- | /bin/sh: passwd: not found | + | |
- | ~ # which passwd | + | |
- | ~ # | + | |
- | </ | + | |
- | + | ||
- | <WRAP center round important> | + | |
- | **Important** - Notez l' | + | |
- | </ | + | |
- | + | ||
- | Pour sortir du conteneur, il convient d' | + | |
< | < | ||
- | ~ # [Ctrl+d] | + | root@debian9: |
- | ~ # root@debian9: | + | Lecture des listes de paquets... Fait |
+ | Construction de l' | ||
+ | Lecture des informations d' | ||
+ | The following additional packages will be installed: | ||
+ | lynx-common | ||
+ | Les NOUVEAUX paquets suivants seront installés : | ||
+ | lynx lynx-common | ||
+ | 0 mis à jour, 2 nouvellement installés, 0 à enlever et 94 non mis à jour. | ||
+ | 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: | ||
</ | </ | ||
- | Le fait de sortir du conteneur ne l' | + | Vérifiez que nginx répond aux requetes |
< | < | ||
- | ~ # root@debian9: | + | root@debian9: |
- | root@debian9: | + | Welcome to nginx! |
- | lxc-bb | + | |
- | root@debian9:~# lxc-ls -f --running | + | |
- | NAME | + | |
- | lxc-bb RUNNING 0 | + | |
- | </ | + | |
- | ===2.5 - Commandes LXC de Base=== | + | If you see this page, the nginx web server is successfully installed |
+ | and working. Further configuration is required. | ||
- | ==La Commande lxc-console== | + | For online documentation and support please refer to [1]nginx.org. |
+ | | ||
- | Pour lancer une console attachée à un TTY dans le conteneur, il convient d' | + | Thank you for using nginx. |
- | < | + | Références |
- | root@debian9: | + | |
- | Connected to tty 1 | + | 1. http:// |
- | Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself | + | 2. http:// |
- | + | ||
- | lxc-bb login: root | + | |
- | Password: | + | |
- | Login incorrect | + | |
- | lxc-bb login: trainee | + | |
- | Password: | + | |
- | Login incorrect | + | |
- | lxc-bb login: | + | |
</ | </ | ||
- | <WRAP center round important> | + | ====1.15 - Arrêter et Démarrer un Conteneur==== |
- | **Important** - Notez que pour des raisons évidentes, le conteneur BusyBox ne sait pas gérer de logins. | + | |
- | </ | + | |
- | Pour sortir de la console, il faut utiliser la combinaison de touches **< | + | Arrêtez le conteneur nginx : |
< | < | ||
- | lxc-bb login: [Ctrl+a] [q] root@debian9: | + | root@debian9:~# docker ps -a |
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9: | ||
+ | aabb | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | ==La Commande lxc-stop== | + | Démarrez de nouveau |
- | + | ||
- | Pour arrêter | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | lxc-bb | + | aabb |
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | root@debian9: | + | aabb064d4b0a |
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | ==La Commande lxc-execute== | + | ====1.16 |
- | La commande **lxc-execute** démarre | + | Utilisez |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | init.lxc.static: | + | aabb |
- | Linux lxc-bb 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux | + | root@debian9: |
- | root@debian9: | + | CONTAINER ID IMAGE |
- | root@debian9: | + | aabb064d4b0a |
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | ==La Commande lxc-info== | + | Redémarrez |
- | + | ||
- | Cette commande donne des informations sur un conteneur : | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | Name: lxc-bb | + | aabb |
- | State: | + | root@debian9: |
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9:~# docker restart aabb | ||
+ | aabb | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | aabb064d4b0a | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | ==La Commande lxc-freeze== | + | ====1.17 |
- | La commande **lxc-freeze** met en pause tous les processus du conteneur : | + | Supprimez un conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | + | Error response from daemon: You cannot remove a running | |
- | root@debian9:~# lxc-ls --running | + | root@debian9: |
- | lxc-bb | + | CONTAINER ID IMAGE |
- | + | aabb064d4b0a | |
- | root@debian9: | + | 4f157e179134 |
- | Name: | + | 04b5ab87539a |
- | State: | + | root@debian9: |
- | PID: 3906 | + | aabb |
- | CPU use: | + | root@debian9: |
- | BlkIO use: 0 bytes | + | CONTAINER ID IMAGE |
- | Memory use: 664.00 KiB | + | 4f157e179134 |
- | KMem use: 340.00 KiB | + | 04b5ab87539a |
- | + | ||
- | root@debian9: | + | |
- | + | ||
- | root@debian9: | + | |
- | Name: | + | |
- | State: | + | |
- | PID: 3906 | + | |
- | CPU use: 0.00 seconds | + | |
- | BlkIO use: | + | |
- | Memory use: | + | |
- | KMem use: | + | |
</ | </ | ||
- | ==La Commande lxc-unfreeze== | + | ===1.18 - Utilisation Simple d'un Volume=== |
- | La commande **lxc-unfreeze** annule l' | + | Créez le fichier index.html et placez-le dans le répertoire / |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | + | root@debian9: | |
- | root@debian9: | + | root@debian9:~# cat index.html |
- | Name: lxc-bb | + | < |
- | State: | + | < |
- | PID: 3906 | + | < |
- | CPU use: 0.00 seconds | + | </ |
- | BlkIO use: 0 bytes | + | </ |
- | Memory use: | + | root@debian9:~# mv index.html www/ |
- | KMem use: 340.00 KiB | + | |
</ | </ | ||
- | ==Autres Commandes== | + | Indiquez au conteneur |
- | + | ||
- | Les autres commandes dont il faut avoir une connaissance sont : | + | |
- | + | ||
- | ^ Commande ^ Description ^ | + | |
- | | lxc-destroy | Permet de détruire complètement un conteneur | + | |
- | | lxc-autostart | Permet de rebooter, tuer ou arrêter les conteneurs dont le drapeau **lxc.start.auto** est fixé dans le fichier | + | |
- | | lxc-cgroup | Permet de manipuler à chaud les CGroups pour un conteneur donné | | + | |
- | | lxc-device | Permet de rajouter à chaud les devices à un conteneur | | + | |
- | | lxc-usernsexec | Permet d' | + | |
- | | lxc-wait | Permet d' | + | |
- | + | ||
- | ===2.6 - Création d'un Conteneur Non-Privilégié=== | + | |
- | + | ||
- | ==User Namespaces== | + | |
- | + | ||
- | Un conteneur privilégié | + | |
- | + | ||
- | Le mappage d'UID est une fonctionnalité du noyau Linux appelée **user namespaces** ou encore **userns**. Cette fonctionnalité permet de mapper une plage d' | + | |
- | + | ||
- | ==Création d'un Utilisateur Dédié== | + | |
- | + | ||
- | Commencez par créer l’utilisateur **lxcnp** dédié à la gestion des conteneurs non-privilégiés | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9: | + | c080793965de8a6a60db212d7e4d96de84b55352c224c054dced75b409e39bf2 |
- | Entrez le nouveau mot de passe UNIX : trainee | + | root@debian9: |
- | Retapez le nouveau mot de passe UNIX : trainee | + | |
- | passwd: password updated successfully | + | |
- | </ | + | |
- | Les informations concernant le mappage des UID et GID se trouvent dans les fichiers **/ | ||
- | < | + | root@debian9: |
- | root@debian9: | + | |
- | / | + | |
- | / | + | |
</ | </ | ||
<WRAP center round important> | <WRAP center round important> | ||
- | **Important** - Ces informations indiquent que nous avons 65 536 UID et 65 536 GID disponibles pour le mappage vers l'UID et le GID **165 536**. | + | **Important** - Notez ici l'utilisation de **ro** - lecture seule. |
</ | </ | ||
- | ==Création du Mappage== | + | ====1.19 - Télécharger une image sans créer un conteneur==== |
- | La valeur | + | Téléchargez l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 0 | + | Using default tag: latest |
+ | latest: Pulling from library/centos | ||
+ | 8ba884070f61: | ||
+ | Digest: sha256: | ||
+ | Status: Downloaded newer image for centos: | ||
</ | </ | ||
- | Fixez donc la valeur à **1** et appliquez la modification avec la commande **sysctl --system** | + | Vérifiez le contenu de l' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~# cat /etc/sysctl.d/80-lxc-userns.conf | + | [root@86252a3f00f4 /]# cat /etc/redhat-release |
- | kernel.unprivileged_userns_clone=1 | + | CentOS Linux release 7.6.1810 (Core) |
- | root@debian9: | + | [root@86252a3f00f4 |
- | * Applying /etc/sysctl.d/80-lxc-userns.conf ... | + | bind-license-9.9.4-73.el7_6.noarch |
- | kernel.unprivileged_userns_clone = 1 | + | bash-4.2.46-31.el7.x86_64 |
- | * Applying /etc/sysctl.d/99-sysctl.conf ... | + | glibc-common-2.17-260.el7_6.3.x86_64 |
- | * Applying /etc/sysctl.conf ... | + | 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-- | ||
</ | </ | ||
- | Connectez-vous ensuite | + | ====1.20 |
+ | |||
+ | Arretez le conteneur. Démarrez le conteneur puis rattachez-vous au conteneur | ||
< | < | ||
- | root@debian9: | + | [root@86252a3f00f4 /]# exit |
- | lxcnp@debian9:~$ | + | exit |
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | 86252a3f00f4 | ||
+ | c080793965de | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9:~# docker start 8625 | ||
+ | 8625 | ||
+ | root@debian9: | ||
+ | [root@86252a3f00f4 /]# ls | ||
+ | anaconda-post.log | ||
+ | [root@86252a3f00f4 /]# | ||
</ | </ | ||
- | Créez le répertoire **~/.config/ | + | ====1.21 - Installer un logiciel dans le conteneur=== |
- | < | + | Créez le fichier **/etc/yum.repos.d/mongodb-org-4.2.repo** : |
- | lxcnp@debian9: | + | |
- | </ | + | |
- | + | ||
- | Créez | + | |
< | < | ||
- | lxcnp@debian9:~$ echo " | + | [root@86252a3f00f4 /]# vi /etc/yum.repos.d/mongodb-org-4.2.repo |
- | + | [root@86252a3f00f4 | |
- | lxcnp@debian9:~$ echo " | + | [mongodb-org-4.2] |
- | + | name=MongoDB Repository | |
- | lxcnp@debian9:~$ echo "lxc.id_map = g 0 165536 65536" >> ~/.config/lxc/default.conf | + | baseurl=https://repo.mongodb.org/ |
- | + | gpgcheck=1 | |
- | lxcnp@debian9:~$ cat ~/.config/lxc/default.conf | + | enabled=1 |
- | lxc.include = /etc/lxc/default.conf | + | gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc |
- | lxc.id_map = u 0 165536 65536 | + | [root@86252a3f00f4 /]# |
- | lxc.id_map = g 0 165536 65536 | + | |
</ | </ | ||
- | Déconnectez-vous et reconnectez-vous en tant que l' | + | Installez mongo : |
< | < | ||
- | lxcnp@debian9: | + | [root@86252a3f00f4 /]# yum install |
- | déconnexion | + | |
- | root@debian9:~# su - lxcnp | + | |
- | lxcnp@debian9: | + | |
</ | </ | ||
- | ==Création du Conteneur== | + | Démarrez mongod |
- | + | ||
- | Créez maintenant un conteneur non-privilégié appelé **lxc-bb-np** à partir du gabarit **busybox** | + | |
< | < | ||
- | lxcnp@debian9:~$ lxc-create | + | [root@86252a3f00f4 /]# mongod |
- | WARN: could not reopen tty: Permission denied | + | [1] 82 |
- | WARN: could not reopen tty: Permission denied | + | [root@86252a3f00f4 /]# about to fork child process, waiting until server is ready for connections. |
- | WARN: could not reopen tty: Permission denied | + | forked process: 84 |
- | WARN: could not reopen tty: Permission denied | + | child process started successfully, |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | WARN: could not reopen tty: Permission denied | + | |
- | chmod: impossible d' | + | |
- | setting | + | |
- | Failed to change root password | + | |
- | lxcnp@debian9: | + | [1]+ Done mongod |
- | total 60 | + | [root@86252a3f00f4 / |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 bin | + | |
- | drwxr-xr-x 4 165536 165536 4096 juil. 29 13:11 dev | + | |
- | drwxr-xr-x 3 165536 165536 4096 juil. 29 13:11 etc | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 home | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 lib | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 lib64 | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 mnt | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 proc | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 root | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 sbin | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 selinux | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 sys | + | |
- | drwxr-xr-x 2 165536 165536 4096 juil. 29 13:11 tmp | + | |
- | drwxr-xr-x 7 165536 165536 4096 juil. 29 13:11 usr | + | |
- | drwxr-xr-x 3 165536 165536 4096 juil. 29 13:11 var | + | |
</ | </ | ||
- | ==Contrôle du Mappage== | + | Vérifiez que mongod est démarré |
- | + | ||
- | Démarrez le conteneur | + | |
< | < | ||
- | lxcnp@debian9:~$ lxc-start -n lxc-bb-np | + | [root@86252a3f00f4 /]# ps aux |
- | lxcnp@debian9: | + | USER PID %CPU %MEM VSZ RSS TTY STAT START |
- | NAME STATE | + | root |
- | lxc-bb-np RUNNING 0 - - | + | root 84 1.2 2.2 294692 46716 ? Sl |
+ | root | ||
</ | </ | ||
- | Attachez-vous au conteneur et contrôlez l'UID de l' | + | Utilisez |
< | < | ||
- | lxcnp@debian9:~$ lxc-attach -n lxc-bb-np | + | [root@86252a3f00f4 /]# mongo |
- | WARN: could not reopen tty: Permission denied | + | MongoDB shell version: 4.2.2 |
- | WARN: could not reopen tty: Permission denied | + | connecting to: test |
- | WARN: could not reopen tty: Permission denied | + | Welcome to the MongoDB shell. |
- | + | For interactive | |
- | + | For more comprehensive documentation, | |
- | BusyBox v1.22.1 (Debian 1: | + | http:// |
- | Enter 'help' for a list of built-in commands. | + | Questions? Try the support group |
- | + | http://groups.google.com/group/mongodb-user | |
- | / # ps aux | + | Server has startup warnings: |
- | PID | + | 2019-04-09T17: |
- | 1 root | + | 2019-04-09T17: |
- | 4 root /bin/syslogd | + | > |
- | 7 root /bin/getty -L tty1 115200 vt100 | + | |
- | 8 root init | + | |
- | | + | |
- | 10 root ps aux | + | |
- | / # | + | |
</ | </ | ||
- | Détachez-vous | + | Sortez de mongo et du conteneur : |
< | < | ||
- | / # exit | + | > exit |
- | lxcnp@debian9: | + | bye |
- | déconnexion | + | [root@86252a3f00f4 /]# exit |
+ | exit | ||
root@debian9: | root@debian9: | ||
</ | </ | ||
- | Dernièrement, | + | ====1.22 - Utilisation |
+ | |||
+ | Créez maintenant une nouvelle image à partir de votre conteneur : | ||
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 165536 | + | CONTAINER ID IMAGE |
- | 165536 | + | 86252a3f00f4 |
- | 165536 | + | c080793965de |
- | 165536 | + | 4f157e179134 |
- | root | + | 04b5ab87539a |
+ | root@debian9:~# docker commit 8625 i2tch/mongodb | ||
+ | sha256:67afc80e1424a6d99179911ee499f6bf264faf2bc3c7ff4ac4a01ff9c23050a9 | ||
</ | </ | ||
- | ===2.7 - Création d'un Conteneur Éphémère=== | + | Supprimez |
- | + | ||
- | Par défaut les conteneurs LXC sont permanents. Il est possible de créer un conteneur éphémère, | + | |
- | + | ||
- | ==La Commande lxc-copy== | + | |
- | + | ||
- | Notez que le conteneur | + | |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | NAME | + | 8625 |
- | lxc-bb RUNNING 0 | + | root@debian9: |
- | + | CONTAINER ID IMAGE | |
- | root@debian9: | + | c080793965de |
- | lxc-copy: lxccontainer.c: | + | 4f157e179134 |
+ | 04b5ab87539a | ||
</ | </ | ||
- | Arrêtez donc le conteneur **lxc-bb** puis créez la copie : | + | Utilisez la nouvelle image pour lancer un conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | root@debian9:~# lxc-ls -f --running | + | [root@d20fb56a38b0 /]# ls / |
- | root@debian9:~# lxc-copy -e -N lxc-bb-eph -n lxc-bb | + | / |
- | Created lxc-bb-eph as clone of lxc-bb | + | / |
+ | [root@d20fb56a38b0 /]# ps aux | ||
+ | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND | ||
+ | root | ||
+ | root 15 0.0 0.1 51748 3468 pts/0 R+ | ||
</ | </ | ||
- | Attachez-vous au conteneur **lxc-bb-eph** | + | Editez le fichier / |
< | < | ||
- | root@debian9:~# lxc-attach lxc-bb-eph | + | [root@d20fb56a38b0 /]# echo "/ |
- | lxc-attach: missing container name, use --name option | + | [root@d20fb56a38b0 /]# tail / |
- | root@debian9:~# lxc-attach -n lxc-bb-eph | + | . " |
+ | fi | ||
+ | fi | ||
+ | done | ||
+ | unset i | ||
+ | unset -f pathmunge | ||
+ | fi | ||
+ | # vim: | ||
+ | / | ||
+ | </ | ||
- | BusyBox v1.22.1 (Debian 1:1.22.0-19+b3) built-in shell (ash) | + | Consultez la liste des conteneurs et relevez le CONTAINER ID du conteneur **mongo** |
- | Enter ' | + | |
- | ~ # | + | < |
+ | [root@d20fb56a38b0 /]# exit | ||
+ | exit | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | d20fb56a38b0 | ||
+ | c080793965de | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
</ | </ | ||
- | Créez un fichier de contrôle appelé **testdata** | + | Utilisez la commande commit pour " |
< | < | ||
- | ~ # ls -l | + | root@debian9:~# docker commit d20f i2tch/mongodb |
- | total 4 | + | sha256:620057baa411b78a0030e192fdfbde0bb0c5ceae7bdeb115892d9946e542ee07 |
- | -rw-r--r-- | + | |
- | ~ # pwd | + | |
- | /root | + | |
- | ~ # echo " | + | |
- | ~ # ls -l | + | |
- | total 8 | + | |
- | -rw-r--r-- | + | |
- | -rw-r--r-- | + | |
- | ~ # | + | |
</ | </ | ||
- | Déconnectez-vous du conteneur puis attachez-vous | + | Démarrez |
< | < | ||
- | ~ # exit | + | root@debian9: |
+ | d20f | ||
+ | root@debian9: | ||
+ | CONTAINER ID IMAGE | ||
+ | c080793965de | ||
+ | 4f157e179134 | ||
+ | 04b5ab87539a | ||
+ | root@debian9: | ||
+ | [root@bcec3f27ed58 /]# about to fork child process, waiting until server is ready for connections. | ||
+ | forked process: 16 | ||
+ | child process started successfully, | ||
- | root@debian9:~# lxc-attach | + | [1]+ Done / |
+ | [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 /]# | ||
+ | </ | ||
+ | ====1.23 - Se connecter au serveur du conteneur de l' | ||
- | BusyBox v1.22.1 (Debian 1:1.22.0-19+b3) built-in shell (ash) | + | Pour pouvoir se connecter à mongodb depuis la machine hôte, il convient d' |
- | Enter ' | + | |
- | ~ # ls -l | + | < |
- | total 8 | + | [root@bcec3f27ed58 /]# vi /etc/mongod.conf |
- | -rw-r--r-- | + | [root@bcec3f27ed58 /]# cat / |
- | -rw-r--r-- | + | |
- | ~ # | + | |
</ | </ | ||
- | <WRAP center round important> | + | Sortez du conteneur, re-créez une image, supprimez |
- | **Important** | + | |
- | </ | + | |
- | + | ||
- | Déconnectez-vous | + | |
< | < | ||
- | ~ # exit | + | [root@bcec3f27ed58 /]# exit |
+ | 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, | ||
- | root@debian9: | + | [1]+ Done |
- | + | [root@d2ddb4f8ca8a | |
- | root@debian9: | + | |
- | lxc-bb | + | |
- | + | ||
- | root@debian9: | + | |
- | lxc-start: log.c: log_open: 300 failed to open log file "/var/lib/lxc/lxc-bb-eph/lxc-bb-eph.log" : No such file or directory | + | |
- | lxc-start: tools/lxc_start.c: | + | |
</ | </ | ||
- | <WRAP center round important> | + | Dans votre machine hôte, configurez |
- | **Important** - Notez que le conteneur **lxc-bb-eph** a été détruit. | + | |
- | </ | + | |
- | + | ||
- | ===2.8 - Sauvegarde des Conteneurs=== | + | |
- | + | ||
- | Un conteneur LXC peut être sauvegardé | + | |
- | + | ||
- | * utiliser la commande **tar** ou **cpio** pour créer un archive du répertoire **rootfs** et du fichier **config** associés au conteneur | + | |
- | * utiliser la commande **lxc-copy** sans l' | + | |
- | * utiliser la commande **lxc-snapshot** | + | |
- | + | ||
- | ==La Commande lxc-snapshot== | + | |
- | + | ||
- | Cette commande permet de gérer des instantanées des conteneurs. A noter que les conteneurs doivent être arrêtés avant de prendre une instantanée | + | |
< | < | ||
- | root@debian9: | + | [root@f5b45072b831 /]# exit |
- | + | root@debian9: | |
- | root@debian9: | + | root@debian9: |
- | lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3407 Snapshot of directory-backed container requested. | + | root@debian9: |
- | lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: | + | root@debian9: |
- | lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3409 please create an aufs or overlayfs clone first, snapshot that | + | Executing: /tmp/apt-key-gpghome.xMuszKS6JM/ |
- | lxc-snapshot: lxccontainer.c: do_lxcapi_snapshot: 3410 and keep the original container pristine. | + | gpg: key 68818C72E52529D4: |
+ | gpg: Total number processed: 1 | ||
+ | gpg: | ||
+ | root@debian9: | ||
+ | root@debian9: | ||
+ | deb http://repo.mongodb.org/ | ||
+ | root@debian9:~# | ||
+ | root@debian9:~# apt-get update | ||
</ | </ | ||
- | Les snapshots sont stockés dans le sous-répertoire **snaps** du répertoire **/ | + | Cette fois, installez uniquement |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | total 12 | + | Lecture des listes de paquets... Fait |
- | -rw-r--r-- | + | Construction de l' |
- | -rw-r--r-- | + | Lecture des informations d' |
- | drwxr-xr-x 17 root root 4096 juil. 28 15:50 rootfs | + | Les NOUVEAUX paquets suivants seront installés : |
- | drwxr-xr-x | + | |
- | + | 0 mis à jour, 1 nouvellement installés, | |
- | root@debian9:~# ls -l /var/lib/lxc/lxc-bb/snaps/ | + | Il est nécessaire de prendre 9 809 ko dans les archives. |
- | total 4 | + | Après cette opération, 39,8 Mo d' |
- | drwxrwx--- 3 root root 4096 juil. 29 17:34 snap0 | + | Réception de:1 http://repo.mongodb.org/apt/debian stretch/ |
- | + | 9 809 ko réceptionnés en 7s (1 245 ko/s) | |
- | root@debian9: | + | Sélection du paquet mongodb-org-shell précédemment désélectionné. |
- | total 12 | + | (Lecture de la base de données... 91513 fichiers et répertoires déjà installés.) |
- | -rw-r--r-- 1 root root 1110 juil. 29 17:34 config | + | Préparation du dépaquetage de .../mongodb-org-shell_4.0.8_amd64.deb ... |
- | drwxr-xr-x 17 root root 4096 juil. 28 15:50 rootfs | + | Dépaquetage de mongodb-org-shell (4.0.8) ... |
- | -rw-r--r-- | + | Paramétrage de mongodb-org-shell (4.0.8) ... |
+ | Traitement des actions différées (« triggers ») pour man-db (2.7.6.1-2) ... | ||
</ | </ | ||
- | L'horodatage de la création du snapshot est stocké dans le fichier **ts** | + | Notez qu'à ce stade le conteneur ne possède pas d' |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 2020:07:29 17:34:36root@debian9:~# | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
</ | </ | ||
- | En comparant la taille du **rootfs** du conteneur | + | Démarrez donc le conteneur |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | 792K / | + | mongo |
- | + | root@debian9: | |
- | root@debian9: | + | " |
- | 792K / | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
</ | </ | ||
- | Pour restaurer un conteneur identique | + | Connectez-vous maintenant |
< | < | ||
- | root@debian9: | + | root@debian9: |
- | + | MongoDB shell version v4.0.8 | |
- | root@debian9:~# lxc-ls | + | connecting to: mongodb:// |
- | lxc-bb | + | WARNING: No implicit session: Logical Sessions are only supported on server versions 3.6 and greater. |
- | + | Implicit session: dummy session | |
- | root@debian9:~# lxc-start -n lxc-bb-snap0 | + | MongoDB server version: 4.2.2 |
- | + | WARNING: shell and server versions do not match | |
- | root@debian9:~# lxc-attach -n lxc-bb-snap0 | + | Welcome to the MongoDB shell. |
- | + | For interactive help, type " | |
- | + | For more comprehensive documentation, | |
- | BusyBox v1.22.1 (Debian 1:1.22.0-19+b3) built-in shell (ash) | + | http:// |
- | Enter ' | + | Questions? Try the support group |
- | + | http://groups.google.com/ | |
- | ~ # exit | + | Server has startup warnings: |
- | root@debian9:~# | + | 2019-04-09T17: |
+ | 2019-04-09T17:31: | ||
+ | > | ||
</ | </ | ||
- | |||
----- | ----- | ||
Ligne 1117: | Ligne 1460: | ||
</ | </ | ||
</ | </ | ||
+ |