{"id":861,"date":"2019-06-10T13:07:19","date_gmt":"2019-06-10T11:07:19","guid":{"rendered":"http:\/\/blogperso.union31.fr\/?p=861"},"modified":"2021-03-12T17:42:21","modified_gmt":"2021-03-12T16:42:21","slug":"linux-docker","status":"publish","type":"post","link":"https:\/\/blogperso.union31.fr\/?p=861","title":{"rendered":"Docker : d\u00e9marrage"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Sommaire<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blogperso.union31.fr\/?p=861\/#I_Mise_en_oeuvre_a_partir_de_Centos_7\" >I Mise en \u0153uvre \u00e0 partir de Centos 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blogperso.union31.fr\/?p=861\/#II_La_gestion_des_images\" >II La gestion des images<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blogperso.union31.fr\/?p=861\/#III_Container_une_instance_dune_image\" >III Container : une instance d&rsquo;une image<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blogperso.union31.fr\/?p=861\/#IV_Enregistrer_ses_modifications\" >IV Enregistrer ses modifications<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"I_Mise_en_oeuvre_a_partir_de_Centos_7\"><\/span>I Mise en \u0153uvre \u00e0 partir de Centos 7<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Installation de docker :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>centos : yum install docker<\/li><li>ubuntu : apt install docker.io<\/li><\/ul>\n\n\n\n<p>D\u00e9marrer puis enregistrer le service :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>systemctl start docker<\/li><li>systemctl enable docker<\/li><\/ul>\n\n\n\n<p><strong>V\u00e9rifier le status d\u2019ex\u00e9cution du service :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>systemctl status docker<\/li><\/ul>\n\n\n\n<p><strong>Connaitre la version install\u00e9e :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker -v<\/li><\/ul>\n\n\n\n<p><strong>Pour v\u00e9rifier que cela fonctionne :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker container<\/strong> <strong>run<\/strong> hello-world<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">Unable to find image 'hello-world:latest' locally\nTrying to pull repository docker.io\/library\/hello-world \u2026\nlatest: Pulling from docker.io\/library\/hello-world\n1b930d010525: Pull complete\nDigest: sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe\nStatus: Downloaded newer image for docker.io\/hello-world:latest\n\nHello from Docker!\n This message shows that your installation appears to be working correctly. <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"II_La_gestion_des_images\"><\/span>II La gestion des images<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>R\u00e9cup\u00e9rer une image existante<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker search<\/strong> guacamole<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">INDEX       NAME                                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\n\ndocker.io   docker.io\/guacamole\/guacamole                    Apache Guacamole is a clientless remote de\u2026   109\n\ndocker.io   docker.io\/guacamole\/guacd                        The native server-side proxy used by Apach\u2026   58\n\ndocker.io   docker.io\/glyptodon\/guacamole                    Guacamole is a clientless remote desktop g\u2026   31                   [OK]\n\ndocker.io   docker.io\/oznu\/guacamole                         A self-contained guacamole docker containe\u2026   24                   [OK]\n\ndocker.io   docker.io\/mattgruter\/guacamole-webserver         Guacamole web application                       11                   [OK]\n...<\/pre>\n\n\n\n<p>Il est propos\u00e9 un tableau de 6 colonnes. les derni\u00e8res sont :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Stars        <\/li><li>officials  : d\u00e9velopp\u00e9e par docker et ses partenaires<\/li><li>automated<\/li><\/ul>\n\n\n\n<p><strong>T\u00e9l\u00e9chargement d&rsquo;une image :<\/strong><\/p>\n\n\n\n<p>Recherche d&rsquo;une image d\u00e9j\u00e0 fabriqu\u00e9e :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker search mailtrap<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">INDEX       NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED\n\ndocker.io   docker.io\/<strong>eaudeweb\/mailtrap<\/strong>          Mail Trap                                       7                    [OK]\n\ndocker.io   docker.io\/ipunktbs\/docker-mailtrap   Mailtrap in docker with roundcube as mail \u2026   2                    [OK]\n\ndocker.io   docker.io\/michielbdejong\/mailtrap    Mailtrap - pipes all incoming emails to th\u2026   1                    [OK]\n\ndocker.io   docker.io\/greatagent\/mailtrap                                                        0\n\ndocker.io   docker.io\/koyaan\/mailtrap            Pipe SMTP to stdout with TLS support            0\n\ndocker.io   docker.io\/motork\/exim4               Image used to catchall email to mailtrap        0\n\ndocker.io   docker.io\/webgriffe\/exim4-mailtrap   Exim4 Docker container with Mailtrap.io su\u2026   0                    [OK]<\/pre>\n\n\n\n<p>T\u00e9l\u00e9chargement de l&rsquo;image qui nous int\u00e9resse :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker image pull <strong>eaudeweb\/mailtrap<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">latest: Pulling from docker.io\/eaudeweb\/mailtrap<br>\ne833e65f6ad9: Downloading [=================================&gt;                 ] 15.18 MB\/22.49 MB<br>\n5b1102297860: Downloading [============&gt;                                      ] 16.62 MB\/68.79 MB<br>\n9874d2a72f1c: Download complete<br>\ncf2e7dee04c6: Download complete<br>\nb81c55fd877e: Download complete<br>\n77601fa2c800: Download complete<br>\nb33371112eac: Downloading [===============================================&gt;   ] 9.943 MB\/10.51 MB<br>\na0a51b8ceb15: Waiting<br>\nf9a413de82e6: Waiting<br>\nf5b73ded68f4: Waiting<\/pre>\n\n\n\n<p>Attendre la fin de l&rsquo;installation<\/p>\n\n\n\n<p>Une fois fini, v\u00e9rification de la pr\u00e9sence de l&rsquo;image en local :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker image ls<\/strong><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE<br>\ndocker.io\/hello-world         latest              fce289e99eb9        5 months ago        1.84 kB<br>\ndocker.io\/eaudeweb\/mailtrap   latest              adfbd16b7ba0        6 months ago        269 MB<\/pre>\n\n\n\n<p>Ici, sont pr\u00e9sent\u00e9s les 2 images t\u00e9l\u00e9charg\u00e9es.<\/p>\n\n\n\n<p><strong>Supprimer une image locale :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker image rm hello-world<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">Error response from daemon: conflict: unable to remove repository reference \"hello-world\" (must force) - container d573bf139bcd is using its referenced image fce289e99eb9<\/pre>\n\n\n\n<p>L&rsquo;image est d\u00e9j\u00e0 instanci\u00e9e, d&rsquo;ou l&rsquo;erreur de suppression. Il faut forcer la suppression avec l&rsquo;option -f :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker image rm <strong>-f<\/strong> hello-world<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">Untagged: hello-world:latest<br>\nUntagged: docker.io\/hello-world@sha256:0e11c388b664df8a27a901dce21eb89f11d8292f7fca1b3e3c4321bf7897bffe<br>\nDeleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e<\/pre>\n\n\n\n<p>L&rsquo;image est effac\u00e9e. V\u00e9rification :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker image ls<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE<br>\ndocker.io\/eaudeweb\/mailtrap   latest              adfbd16b7ba0        6 months ago        269 MB<\/pre>\n\n\n\n<p>Il ne reste bien qu&rsquo;une image sur le disque en local.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"III_Container_une_instance_dune_image\"><\/span>III Container : une instance d&rsquo;une image<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Un container est une instance d&rsquo;une image stock\u00e9e en local. Pour la lancer il ex\u00e9cuter la commande suivante :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker container run<\/strong> eaudeweb\/mailtrap<\/li><\/ul>\n\n\n\n<p>Set the &lsquo;ServerName&rsquo; directive globally to suppress this message<br>\n.<br>\n==&gt; \/var\/log\/apache2\/error.log &lt;==<br>\n[Mon Jun 10 15:14:47.935923 2019] [mpm_prefork:notice] [pid 187] AH00163: Apache\/2.4.25 (Debian) configured &#8212; resuming normal operations<br>\n[Mon Jun 10 15:14:47.936009 2019] [core:notice] [pid 187] AH00094: Command line: &lsquo;\/usr\/sbin\/apache2&rsquo;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">==&gt; \/var\/log\/mail.log &lt;==<br>\nJun 10 15:14:47 5c4ff61f45c7 postfix[108]: Postfix is running with backwards-compatible default settings<br>\nJun 10 15:14:47 5c4ff61f45c7 postfix[108]: See http:\/\/www.postfix.org\/COMPATIBILITY_README.html for details<br>\nJun 10 15:14:47 5c4ff61f45c7 postfix[108]: To disable backwards compatibility use \"postconf compatibility_level=2\" and \"postfix reload\"<br>\nJun 10 15:14:47 5c4ff61f45c7 postfix\/master[155]: daemon started -- version 3.1.8, configuration \/etc\/postfix<br>\nJun 10 15:14:47 5c4ff61f45c7 dovecot: master: Dovecot v2.2.27 (c0f36b0) starting up for imap<br>\nJun 10 15:14:47 5c4ff61f45c7 dovecot: ssl-params: Generating SSL parameters<br>\nJun 10 15:14:53 5c4ff61f45c7 dovecot: ssl-params: SSL parameters regeneration completed<\/pre>\n\n\n\n<p>Une fois la commande lanc\u00e9e, le shell ne rend pas la main&#8230; L&rsquo;instance est bien en cours d&rsquo;\u00e9xecution &#8230; mais il va falloir ouvrir un autre terminal pour reprendre la main.<\/p>\n\n\n\n<p> Pour voir les containers (instances) en cours d\u2019ex\u00e9cution :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker container ls<\/strong><\/li><\/ul>\n\n\n\n<p>CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES<br> <span style=\"text-decoration: underline;\">5c4ff61f45c7 <\/span>       eaudeweb\/mailtrap   \u00ab\u00a0\/var\/local\/docker\u2026\u00a0\u00bb   5 minutes ago       Up 5 minutes        25\/tcp, 80\/tcp      lucid_goldberg<\/p>\n\n\n\n<p>Commande plus rapide :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker ps<\/strong><\/li><\/ul>\n\n\n\n<p>Pour tuer le processus :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>docker container kill<\/strong> <span style=\"text-decoration: underline;\">5c4ff61f45c7<\/span><\/li><\/ul>\n\n\n\n<p>Pour relancer le container mais de mani\u00e8re interactive :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>docker container run<\/strong> <strong><span style=\"text-decoration: underline;\">-it<\/span><\/strong> eaudeweb\/mailtrap <\/li><\/ul>\n\n\n\n<p>Le CTRL C fonctionnera &#8230;.<\/p>\n\n\n\n<p>Le container est lanc\u00e9. Pour savoir quels sont les ports d&rsquo;\u00e9coutes :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker container ls -a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS               NAMES\n\ncf77df238d6d        adfbd16b7ba0        \"\/var\/local\/docker\u2026\"   About a minute ago   Up About a minute   <strong>25\/tcp<\/strong>, <strong>80\/tcp<\/strong>      loving_booth<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>A noter que les instances ne sont pas persistantes. Au prochain d\u00e9marage \u00e0 partir de l&rsquo;image, toutes les modifications seront perdues.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"IV_Enregistrer_ses_modifications\"><\/span>IV Enregistrer ses modifications<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p> Lancer un contenair centos<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker run -ti centos<\/li><\/ul>\n\n\n\n<p>L&rsquo;image n&rsquo;existant pas, elle automatiquement t\u00e9l\u00e9charg\u00e9e. Une fois le container ex\u00e9cut\u00e9 en interactif (option -ti), nous nous retrouvons dans l&rsquo;instance :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> [root@localhost ~]# docker run -it centos\n <strong>[root@1b57648a34da \/]<\/strong># ls\n anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var<\/pre>\n\n\n\n<p>Cr\u00e9ation d&rsquo;un fichier dans ce container :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>touch \/test.txt<\/li><\/ul>\n\n\n\n<p>A partir d&rsquo;un autre terminal :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker ps<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES<br>\nc6ea6139f3f7        centos              \"\/bin\/bash\"         12 minutes ago      Up 12 minutes                           naughty_darwin<\/pre>\n\n\n\n<p>Pour voir les diff\u00e9rences apport\u00e9es :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker diff c6ea6139f3f7<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">C \/run\nD \/run\/secrets\nA \/test.txt<\/pre>\n\n\n\n<p>Nous voyons bien notre nouveau fichier. Pour enregistre les modifications, il faut utiliser l&rsquo;option commit :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker<strong> commit<\/strong> c6ea6139f3f7 centos-test<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@localhost ~]# docker commit c6ea6139f3f7 centos-test\n sha256:1b5c255408dd8b7c99803dd6456aea629a84be385344f61a900a3ede1530db23\n<\/pre>\n\n\n\n<p>Ainsi une nouvelle image est cr\u00e9\u00e9e :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker images<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">REPOSITORY                    TAG                 IMAGE ID            CREATED              SIZE\n\n<strong>centos-test                   latest              1b5c255408dd        About a minute ago   202 MB<\/strong>\n\ndocker.io\/centos              latest              9f38484d220f        2 months ago         202 MB\n\ndocker.io\/eaudeweb\/mailtrap   latest              adfbd16b7ba0        6 months ago         269 MB<\/pre>\n\n\n\n<p>Maintenant si on lance la nouvelle image (docker run -ti centos-test) nous aurons le fichier test \u00e0 la racine de l&rsquo;OS.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>V Sauvegarder l&rsquo;image<\/p>\n\n\n\n<p>Cr\u00e9ation d&rsquo;un r\u00e9pertoire :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>mkdir ~\/lab<\/li><\/ul>\n\n\n\n<p>Sauvegarde :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>docker save centos-test &gt; ~\/lab\/centos-test.tar<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">[root@localhost lab]# ls -als\n total 204596\n      0 drwxr-xr-x. 2 root root        29 10 juin  19:01 .\n      0 dr-xr-x---. 3 root root       146 10 juin  19:00 ..\n 204596 -rw-r--r--. 1 root root 209502720 10 juin  19:01 centos-test.tar<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I Mise en \u0153uvre \u00e0 partir de Centos 7 Installation de docker : centos : yum install docker ubuntu : apt install docker.io D\u00e9marrer puis enregistrer le service : systemctl start docker systemctl enable docker V\u00e9rifier le status d\u2019ex\u00e9cution du<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-861","post","type-post","status-publish","format-standard","hentry","category-_systeme"],"_links":{"self":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=861"}],"version-history":[{"count":35,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions"}],"predecessor-version":[{"id":2193,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=\/wp\/v2\/posts\/861\/revisions\/2193"}],"wp:attachment":[{"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogperso.union31.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}