<?xml version="1.0" encoding="UTF-8"?>
<chapter annotations="slide" version="5.1" xml:id="sdiDocker_chap"
         xmlns="http://docbook.org/ns/docbook"
         xmlns:xlink="http://www.w3.org/1999/xlink"
         xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
         xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:trans="http://docbook.org/ns/transclusion"
         xmlns:svg="http://www.w3.org/2000/svg"
         xmlns:m="http://www.w3.org/1998/Math/MathML"
         xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:db="http://docbook.org/ns/docbook">
  <title>Docker</title>

  <section xml:id="sdiDocker_sect_introduction">
    <title>Introduction</title>

    <figure xml:id="sdiDocker_figInstall">
      <title>Installation</title>

      <itemizedlist>
        <listitem>
          <para><uri
          xlink:href="https://docs.docker.com/install">https://docs.docker.com/install</uri></para>
        </listitem>

        <listitem>
          <para><link
          xlink:href="https://github.com/wsargent/docker-cheat-sheet">Docker
          Cheat Sheet</link></para>
        </listitem>
      </itemizedlist>
    </figure>

    <figure xml:id="sdiDocker_Hub">
      <title>Docker hub</title>

      <para>Repository hosting publicly available Docker images:</para>

      <para><uri
      xlink:href="https://hub.docker.com/explore">https://hub.docker.com/explore</uri></para>
    </figure>

    <section xml:id="sdiDocker_manageImages_sect">
      <title>Managing images</title>

      <figure xml:id="sdiDocker_figSearchImages">
        <title>Search images</title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/search">docker search</link> nextcloud
NAME                       DESCRIPTION      <link
            xlink:href="https://docs.docker.com/docker-hub/repos/#stars">STARS</link>  <link
            xlink:href="https://docs.docker.com/docker-hub/official_repos">OFFICIAL</link>   <link
            xlink:href="https://docs.docker.com/docker-cloud/builds/automated-build">AUTOMATED</link>
nextcloud                  A safe home …    424    [OK]
linuxserver/nextcloud      A Nextcloud …    56
greyltc/nextcloud          Nextcloud: …     34                [OK]
wonderfall/nextcloud       All-in-one …     27                [OK]
rootlogin/nextcloud        Nextcloud …      17                [OK]
lsioarmhf/nextcloud        ARMHF based …    8
ownyourbits/nextcloudpi    NextCloud ARM …  7
...</screen>
      </figure>

      <figure xml:id="sdiDocker_figPullImage">
        <title>Pull image using <xref linkend="glo_CLI"/></title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/image_pull">docker image pull</link> alpine
Using default tag: latest
latest: Pulling from library/alpine
<emphasis role="red">ff3a5c916c92</emphasis>: Pull complete
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest</screen>
      </figure>

      <figure xml:id="sdiDocker_figPullNextcloudImage">
        <title>Pull <productname>Nextcloud</productname> image</title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/pull">docker image pull</link> <emphasis
            role="bold">wonderfall/nextcloud</emphasis> <co
            linkends="sdiDocker_figPullNextcloudImage-1"
            xml:id="sdiDocker_figPullNextcloudImage-1-co"/>
Using default tag: latest <co linkends="sdiDocker_figPullNextcloudImage-2"
            xml:id="sdiDocker_figPullNextcloudImage-2-co"/>
latest: Pulling from wonderfall/nextcloud
<emphasis role="red">ff3a5c916c92</emphasis>: Already exists <co
            linkends="sdiDocker_figPullNextcloudImage-3"
            xml:id="sdiDocker_figPullNextcloudImage-3-co"/>
a542d4c3cffb: Pull complete <co linkends="sdiDocker_figPullNextcloudImage-4"
            xml:id="sdiDocker_figPullNextcloudImage-4-co"/>
83001cc0bea0: Pull complete
41a33c66b2c1: Pull complete
a70bf67726f3: Pull complete
fea90b3d29ac: Pull complete
Digest: sha256:472c5c7...2ca20cca45 <co
            linkends="sdiDocker_figPullNextcloudImage-5"
            xml:id="sdiDocker_figPullNextcloudImage-5-co"/>
Status: Downloaded newer image for wonderfall/nextcloud:latest</screen>
      </figure>

      <calloutlist>
        <callout arearefs="sdiDocker_figPullNextcloudImage-1-co"
                 xml:id="sdiDocker_figPullNextcloudImage-1">
          <para>Get docker image from remote server.</para>
        </callout>

        <callout arearefs="sdiDocker_figPullNextcloudImage-2-co"
                 xml:id="sdiDocker_figPullNextcloudImage-2">
          <para>Version defaults to »latest«: Subject to be overridden.</para>
        </callout>

        <callout arearefs="sdiDocker_figPullNextcloudImage-3-co"
                 xml:id="sdiDocker_figPullNextcloudImage-3">
          <para>Reference to existing <link
          linkend="sdiDocker_figPullImage">»alpine« layer</link>.</para>
        </callout>

        <callout arearefs="sdiDocker_figPullNextcloudImage-4-co"
                 xml:id="sdiDocker_figPullNextcloudImage-4">
          <para>Layer downloads.</para>
        </callout>

        <callout arearefs="sdiDocker_figPullNextcloudImage-5-co"
                 xml:id="sdiDocker_figPullNextcloudImage-5">
          <para>Hash value allowing for image verification.</para>
        </callout>
      </calloutlist>

      <figure xml:id="sdiDocker_figNextcloudFromAlpine">
        <title><productname>Nextcloud</productname> based on
        <productname>Alpine</productname></title>

        <mediaobject>
          <imageobject>
            <imagedata fileref="Ref/Docker/layer.multi.svg"/>
          </imageobject>
        </mediaobject>
      </figure>

      <figure xml:id="sdiDocker_inspectImage_fig">
        <title><link
        xlink:href="http://www.googlinux.com/list-all-tags-of-docker-image/index.html">Inspect
        image</link></title>

        <screen>&gt; docker image inspect dac77467ddcc
[
    {
        "Id": "sha256:dac77467ddccc2287d99558245bd34707...",
        "RepoTags": [
            "nextcloud:13.0.4"
        ],
        "RepoDigests": [
            "nextcloud@sha256:fb3e77f19b21364925e8f02..."
        ],
 ...</screen>
      </figure>

      <figure xml:id="sdiDocker_figSearchImageTags">
        <title><link
        xlink:href="http://www.googlinux.com/list-all-tags-of-docker-image/index.html">Search
        an image's tags</link></title>

        <screen>&gt; curl 'https://registry.hub.docker.com/v2/repositories/library/<emphasis
            role="red">nextcloud</emphasis>/tags/'|\
      jq '."results"[]["name"]'  <emphasis role="red"># requires »aptitude install curl jq«</emphasis>
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 11856    0 11856    0     0  11856      0 --:--:-- --:--:-- --:--:-- 20371
"fpm"
"production"
"stable"
"latest"
"13"
"13.0"
"13.0.2"
"production-apache"
"stable-apache"
"apache"</screen>
      </figure>

      <figure xml:id="sdiDocker_figNextcloudImageByVersion">
        <title><productname>Nextcloud</productname> image by version</title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/pull">docker image pull</link> nextcloud:13.0.4
13.0.4: Pulling from library/nextcloud
3d77ce4481b1: Pull complete
32bfdb6043a8: Pull complete
028453741593: Pull complete
f93d7bd342a3: Pull complete
4a2fac611953: Pull complete
87fdfc7d0f94: Pull complete
Digest: sha256:<emphasis role="red">fb3e77f19b21364925e8f02d6e5ad3a1</emphasis> ...
Status: Downloaded newer image for <emphasis role="red">nextcloud:13.0.4</emphasis></screen>
      </figure>

      <figure xml:id="sdiDocker_figListImages">
        <title>List images by <xref linkend="glo_CLI"/></title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/image">docker image ls</link>
REPOSITORY            TAG      IMAGE ID       CREATED        SIZE
nextcloud             13.0.4   dac77467ddcc   3 days ago     544MB
wonderfall/nextcloud  latest   57e1fb51b334   2 months ago   328MB
alpine                latest   3fd9065eaf02   4 months ago   4.15MB</screen>
      </figure>

      <figure xml:id="sdiDocker_figNextcloudImageLatest">
        <title><productname>Nextcloud</productname> latest image</title>

        <screen>&gt; <link
            xlink:href="https://docs.docker.com/engine/reference/commandline/pull">docker image pull</link> nextcloud
Using default tag: latest
latest: Pulling from library/nextcloud <co
            linkends="sdiDocker_figNextcloudImageByVersion-1"
            xml:id="sdiDocker_figNextcloudImageByVersion-1-co"/>
Digest: sha256:<emphasis role="red">fb3e77f19b21364925e8f02d6e5ad3a1</emphasis> ... <co
            linkends="sdiDocker_figNextcloudImageByVersion-2"
            xml:id="sdiDocker_figNextcloudImageByVersion-2-co"/>
Status: Downloaded newer image for <emphasis role="red">nextcloud:latest</emphasis></screen>
      </figure>

      <calloutlist>
        <callout arearefs="sdiDocker_figNextcloudImageByVersion-1-co"
                 xml:id="sdiDocker_figNextcloudImageByVersion-1">
          <para>No »<link
          xlink:href="https://docs.docker.com/engine/reference/commandline/pull/#examples">Pull
          complete</link>« messages, image is alias of
          <code>nextcloud:13.0.4</code>.</para>
        </callout>

        <callout arearefs="sdiDocker_figNextcloudImageByVersion-2-co"
                 xml:id="sdiDocker_figNextcloudImageByVersion-2">
          <para>Digest value identical to <xref
          linkend="sdiDocker_figNextcloudImageByVersion"/>.</para>
        </callout>
      </calloutlist>

      <figure xml:id="sdiDocker_figListNextcloudImages">
        <title>Duplicate <productname>Nextcloud</productname> images</title>

        <screen>&gt; docker image ls 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nextcloud           13.0.4              <emphasis role="red">dac77467ddcc</emphasis>        4 days ago          <emphasis
            role="red">544MB</emphasis>
nextcloud           latest              <emphasis role="red">dac77467ddcc</emphasis>        4 days ago          <emphasis
            role="red">544MB</emphasis>
...</screen>
      </figure>

      <figure xml:id="sdiDocker_figCompareMavenArtifacts">
        <title>Maven ringing a bell?</title>

        <programlisting language="xml">&lt;dependency&gt;
  &lt;groupId&gt;<emphasis role="red">junit</emphasis>&lt;/groupId&gt;           &lt;!-- <emphasis
            role="red">wonderfall</emphasis> --&gt;
  &lt;artifactId&gt;<emphasis role="red">junit</emphasis>&lt;/artifactId&gt;     &lt;!-- <emphasis
            role="red">nextcloud</emphasis> --&gt;
  &lt;version&gt;<emphasis role="red">4.12</emphasis>&lt;/version&gt;            &lt;!-- <emphasis
            role="red">13.0.4</emphasis> --&gt;
&lt;/dependency&gt;</programlisting>
      </figure>

      <figure xml:id="sdiDocker_figUntagImage_fig">
        <title>Un tag image by version</title>

        <screen>&gt; docker image rm nextcloud:latest
Untagged: nextcloud:latest

&gt; docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nextcloud           13.0.4              dac77467ddcc        4 days ago          544MB
...</screen>
      </figure>

      <figure xml:id="sdiDocker_figRemoveImage_fig">
        <title>Remove image by version</title>

        <screen>&gt; docker image rm nextcloud:13.0.2
Untagged: nextcloud:latest
Untagged: nextcloud@sha256:c693921e69cb89cd0bee7c014280159df647e5ba87f54c895650156d973df035
Deleted: sha256:10ae267ddcf25bfe5cc059685d3d005bcfe7229b44c3a6f93e0a07795d33b5b2
Deleted: sha256:1c271f4f2f19a222cd116c771b02294c5dd596fa8a0366559061f83a0de8de3f
...
Deleted: sha256:2c833f307fd8f18a378b71d3c43c575fabdb88955a2198662938ac2a08a99928</screen>
      </figure>
    </section>

    <section xml:id="sdiDocker_runningContainer_sect">
      <title>Running container</title>

      <figure xml:id="sdiDocker_fig_startNexctcloud">
        <title>Starting <productname>Nextcloud</productname> container</title>

        <screen>&gt; docker run -d -p 8080:80 --name nc13 nextcloud
517e3dba488763eb615f2c68d417e1b7fb3a9ce5bb4a5ffc346dcb86c00d13d2</screen>
      </figure>

      <figure xml:id="sdiDocker_figListContainer">
        <title>List running containers</title>

        <screen>&gt; docker ps -a
CONTAINER ID  IMAGE      COMMAND                ... PORTS                 NAMES
517e3dba4887  nextcloud  "/entrypoint.sh apac…" ... 0.0.0.0:8080-&gt;80/tcp  <emphasis
            role="red">nc13</emphasis></screen>
      </figure>

      <figure xml:id="sdiDocker_figKillProcess">
        <title>Remove container</title>

        <screen>&gt; docker rm <emphasis role="red">nc13</emphasis>
nc13</screen>

        <screen>&gt; docker ps -a
CONTAINER ID   IMAGE       COMMAND             CREATED      STATUS                   ... NAMES</screen>
      </figure>
    </section>
  </section>

  <section xml:id="sdiDocker_sect_exercises">
    <title>Exercises</title>

    <para>In this exercise you are about to replace your package based
    <productname>Nextcloud</productname> installation by a
    <productname>Docker</productname> container based on an already existing
    image.</para>
  </section>
</chapter>