    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: A Brief Introduction to Docker</title>
        <link>https://members.accu.org/index.php/articles/2437</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Programming Topics + CVu Journal Vol 29, #5 - November 2017</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c65/">Programming</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c379/">295</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c65-379/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c65+379/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;A Brief Introduction to Docker</h1>
<p><strong>Author:</strong>&nbsp;Bob Schmidt</p>
<p>
<strong>Date:</strong> 08 November 2017 17:00:11 +00:00 or Wed, 08 November 2017 17:00:11 +00:00</p>
<p><strong>Summary:</strong>&nbsp;Silas S. Brown shares his experiences of setting up a virtual appliance.</p>
<p><strong>Body:</strong>&nbsp;<p>Docker is basically a convenient way of setting up chroot jails on the GNU/Linux platform, but some companies now use it to deploy software to their servers. Docker is like having a lightweight virtual machine, except only on Linux (donâ€™t expect to be able to run it on Windows or Mac except inside a Linux VM). One advantage of Docker over virtual machines is ease of initial setup. For example, on several versions of Red Hat Linux as used in some corporate environments, Virtualbox wonâ€™t run without significant extra effort, but Docker â€˜just worksâ€™. Want to do something on a virtual Debian box? Install Docker, ensure <code>sudo dockerd</code> is running, and do:</p>

<pre class="programlisting">
  docker pull debian
  docker run -it debian /bin/bash</pre>
  
<p>and you should be away (except youâ€™ll need an <code>apt-get update</code> before doing any serious amount of package installation).</p>

<p>But as soon as that first shell exits, any changes you made to the system (such as installing extra packages and changing the configuration) will be lost. That might be OK for a one-off experiment, but for serious use you probably want some of the configuration to persist. Thatâ€™s usually done by writing build instructions for your own derived Docker image.</p>

<p>Just as the <code>make</code> command uses a file typically named Makefile, so Docker uses a file called Dockerfile, which should be placed at the top of your source tree (or at least the part of it relevant to the Docker image youâ€™re creating). Dockerfiles almost always name an existing GNU/Linux distribution to use as a base, followed by files or directories to copy into the container and setup commands to run:</p>

<pre class="programlisting">
  FROM centos:6.8
  COPY myDirectory /etc/myDirectory
  COPY src/*.c /home/user/src/
  RUN yum install -y myPackage</pre>
  
<p>but if you need to start daemons, you shouldnâ€™t do so as an effect of the <code>RUN</code> commands here, since these run only when the image is generated, not every time itâ€™s started. You may add a single <code>CMD</code> command to the Dockerfile saying what command should be run when <code>docker run</code> is called on the image (thereâ€™s also an alternative called <code>ENTRYPOINT</code> which can take additional command-line arguments from the <code>docker run</code> command, in which case <code>CMD</code> is repurposed to specify default arguments to add when these are missing), and this will be responsible for starting any necessary daemons, running the foreground process, and, if necessary, cleanly shutting down the daemons afterwards (otherwise theyâ€™ll all be aborted as soon as the master process exits).</p>

<p>It may also be worth noting that Docker will try to cache all intermediate states between commands in the Dockerfile, so combining multiple <code>RUN</code> commands into one can save disk space. (<code>RUN</code> commands are also expected to produce practically-identical results each time they are run: the cache will be refreshed if the source file of a <code>COPY</code> is changed, but it will not be refreshed just because the expected result of some <code>RUN</code> command changes unless the <code>RUN</code> command itself is changed. This might affect you if you try to install your own work via a network-fetching <code>RUN</code> instead of via a <code>COPY</code>: changes you make upstream will not be reflected in the Docker build, unless you give Docker some other reason to invalidate its cache before reaching that <code>RUN</code>, such as by making changes to a file thatâ€™s <code>COPY</code>â€™d in first.)</p>

<p>Base images can be found on <a href="https://hub.docker.com/explore/">https://hub.docker.com/explore/</a> but the presence of application-specific base images (nginx, golang etc) is slightly misleading: you canâ€™t â€˜importâ€™ multiple applications by depending on multiple base images, so itâ€™s not as much of a â€˜package managerâ€™ as it seems. Granted, if you need one base environment to compile something, but then wish to copy only its final binary into another base environment (discarding the compiler etc), you can do this with Dockerâ€™s â€˜multi-stage buildsâ€™:</p>

<pre class="programlisting">
  FROM golang:1.7.3 as builder
  RUN build-my-Go-program
  FROM centos:6.8
  COPY --from=builder /path/to/my/binary .</pre>
  
<p>but youâ€™d then have to make sure all the right libraries are in the final image. This might be useful if you need a compiler thatâ€™s harder to set up on all development machines due to distribution differences, and donâ€™t want the bloat of putting the compiler in the final image. But beyond this, there unfortunately doesnâ€™t yet seem to be a way of asking Docker to â€˜mergeâ€™ base images, so you canâ€™t use Docker itself as a package manager. At least it makes it easier to obtain minimal distributions (which can be different from the distribution youâ€™re running) and use their own package managers. Please change the distroâ€™s package-manager configuration to use your nearest mirror before downloading large packages with it, especially in a Docker image thatâ€™s likely to be re-built frequently (in extreme cases it might even be a good idea to cache some packages locally).</p>

<p>Further documentation can be found on docker.com; the <code>EXPOSE</code> command is worth a look if you want to run a server inside the container that you wish to be visible from the outside.</p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
