
\begin{exe} {Install and test \textbf{Apache} (\textbf{httpd}) as a \textbf{Docker} application.}

   \begin{lfbox}[Overview]
      In this exercise, we will install, run and test the
      \textbf{docker} package, and follow with getting and
      deploying \textbf{httpd}, the \textbf{Apache} web server
      container.
   \end{lfbox}

   \begin{redhatfamilybox}
      Please note that \textbf{RHEL/CentOS 8} and recent
      \textbf{Fedora} distributions utilized
      \textbf{podman}. On these systems \textbf{docker} is
      supported by a backwards compatibility layer:

      \begin{cmd}
$ sudo dnf install podman podman-docker
    \end{cmd}
   \end{redhatfamilybox}

   \begin{enumerate}
      \item
      Make sure \textbf{Docker} is installed (or emulated with
      \textbf{podman}.)  Pick the right command for your
      distribution:
      \begin{cmd}
$ sudo yum install docker                # RHEL/CentOS 7
$ sudo dnf install podman podman-docker  # RHEL/CentOS 8, Fedora      
$ sudo apt-get install docker.io             # Ubuntu, Debian
$ sudo zypper install docker             # openSUSE
      \end{cmd}

      \begin{info}[Reinstall Docker?]
         \begin{itemize}
            \item
            If you get strange errors at later points in the
            exercise you might find it useful to
            \textbf{reinstall} \textbf{docker}.  We have
            observed cases (for example, with \textbf{RHEL 7})
            where \textbf{docker} configurations were broken,
            after a system upgrade,
         \end{itemize}
      \end{info}

      \item
      Start the \textbf{docker} service:

      \begin{important}
         You can skip to the next step on \textbf{podman}-based
         systems as there is no \textbf{docker} service to start!
      \end{important}

      \begin{cmd}
$ sudo systemctl start docker
      \end{cmd}
      You may want to verify that it is running properly with
      \verb? systemctl status docker?:

      \begin{figure}[H]
         \includegraphics[width=7in]{IMAGES/docker-status}
         \caption{Checking docker status}
      \end{figure}
      If you see anything indicating failure you should inspect
      \filelink{/var/log/messages} or whatever other logging file
      you have on your system for clues.  If you are running a
      standard distribution kernel you should be fine, but
      if you are running a custom \textbf{Linux} kernel, it is
      likely you have to select the proper configuration options,
      especially as regards to networking.  This is too complicated
      to go into here, so please stay with a distribution supplied
      kernel unless you want a challenging exercise!
      \item
      Search for the \textbf{httpd} container, with
      \begin{cmd}
$ sudo docker search apache
        \end{cmd}
      \begin{figure}[H]
         \includegraphics[width=7in]{IMAGES/docker-search}
         \caption{Using docker search}
      \end{figure}
      (You could have used \textbf{httpd} instead of
      \textbf{apache} in the above command with very similar
      results.)

      From now on we will not show detailed output since if
      you have gotten this far, things should be fine.
      \item
      Retrieve the container:
      \begin{cmd}
$ sudo docker pull docker.io/httpd
      \end{cmd}
      This may take a couple of minutes while all the
      components download.
      \item
      List the installed containers:
      \begin{cmd}
$ sudo docker images
      \end{cmd}
      \item
      List the components associated with the images.
      \begin{cmd}
$ sudo  docker images --all
      \end{cmd}
      \item
      Start the \textbf{httpd} \textbf{docker} container.
      The terminal will appear to hang as it is now
      connected to the \textbf{httpd} daemon.
      \begin{cmd}
c7:/tmp>sudo docker run httpd

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, 
   using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
......
      \end{cmd}
      \item
      You can open a graphical web browser pointing to the
      IP address in the above output. (Do not use the address shown in
      the output above!)

      Or you can use a text-based browser (especially if you
      are not in a graphical environment) by opening up a
      new terminal window (do not kill the one in which the
      \textbf{docker httpd} container is running!) and doing
      one of the following commands:
      \begin{cmd}
$ lynx   http://172.17.0.2
$ w3m    http://172.17.0.2
$ elinks http://172.17.0.2
      \end{cmd}
      using whichever text-based browser is installed on your system.
      \item
      Stop the container and \textbf{docker} service and
      clean up.
      \begin{cmd}
c7:/tmp>sudo docker ps
      \end{cmd}
      \begin{responsevar}{\footnotesize}
         CONTAINER ID    IMAGE    COMMAND              CREATED           STATUS            PORTS       NAMES
         b936b0afeb23    httpd    "httpd-foreground"   41 seconds ago    Up 40 seconds     80/tcp      boring_turing
      \end{responsevar}
      \begin{cmd}
c7:/tmp>sudo docker stop b936b0afeb23
      \end{cmd}
      \begin{response}
b936b0afeb23
      \end{response}
      \item
      This will leave images and their associated storage
      under either \filelink{/var/lib/docker} or
      \filelink{/var/lib/containers} depending on your
      particular system and distribution. If you do not need
      to reuse them you can clean up with:
      \begin{cmd}
c7:/tmp>sudo docker rmi -f docker.io/httpd
Untagged: docker.io/httpd:latest
Untagged: docker.io/httpd@sha256:cf774f082e92e582d02acdb76dc84e61dcf5394a90f99119d1ae39bcecbff075
Deleted: sha256:cf6b6d2e846326d2e49e12961ee0f63d8b5386980b5d3a11b8283151602fa756
      \end{cmd}
      and on some systems you may also need to do:
      Deleted Containers:
      \begin{cmd}
c7:/tmp>sudo docker system prune -a
.....
      \end{cmd}
      On non-\textbf{podman} systems you may also want to do:
      \begin{cmd}      
c7:/tmp>sudo systemctl stop docker
      \end{cmd}
   \end{enumerate}

\end{exe}

