<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Oracle Sean  ♠️</title>
    <description>The latest articles on DEV Community by Oracle Sean  ♠️ (@oraclesean).</description>
    <link>https://dev.to/oraclesean</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F261306%2Fb063645a-c1e9-4f4e-8191-d5c971e53a0d.jpg</url>
      <title>DEV Community: Oracle Sean  ♠️</title>
      <link>https://dev.to/oraclesean</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oraclesean"/>
    <language>en</language>
    <item>
      <title>Visual Docker: Images are Immutable</title>
      <dc:creator>Oracle Sean  ♠️</dc:creator>
      <pubDate>Fri, 07 Apr 2023 11:07:15 +0000</pubDate>
      <link>https://dev.to/oraclesean/visual-docker-images-are-immutable-ngm</link>
      <guid>https://dev.to/oraclesean/visual-docker-images-are-immutable-ngm</guid>
      <description>&lt;h2&gt;
  
  
  Changing an image alters the rules mid-game
&lt;/h2&gt;

&lt;p&gt;This is the second article in a series dedicated to visually explaining Docker and container concepts using a game of Tic-Tac-Toe and little or no code. It's focused on image immutability and tags, and demonstrates why images can't change.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://dev.to/oraclesean/visual-docker-images-and-containers-48d9"&gt;last post&lt;/a&gt; in this series used a game of Tic-Tac-Toe to show how containers are thin layers projected onto images. The image is the Tic-Tac-Toe board and includes the game's rules. It's shared by every Tic-Tac-Toe game container. Individual containers are layers that start out empty. As players add moves, they're recorded in the container layer.&lt;/p&gt;

&lt;p&gt;The game only makes sense when you see both pieces together. On its own, the container layer is just random X's and O's. The game board in the image is perpetually empty because it can't change. In the container world, we say that images are &lt;em&gt;immutable&lt;/em&gt; and, therefore, also &lt;em&gt;stateless&lt;/em&gt; since altering the state requires saving those changes somewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change ≠ Replace
&lt;/h2&gt;

&lt;p&gt;Is that really true, though? After all, I can change a Dockerfile and rebuild the image using the same name, which would seem to change the image. More accurately, I &lt;em&gt;replaced&lt;/em&gt; the old image and assigned the same name.&lt;/p&gt;

&lt;p&gt;It's an important distinction. To illustrate why, let's list the images on the system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; docker images
REPOSITORY   TAG           IMAGE ID       CREATED      SIZE
games        tic-tac-toe   ec616ed52b3b   1 hour ago   100KB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, start a new game container using that image. The "friendly" image name is its &lt;code&gt;REPOSITORY&lt;/code&gt; and &lt;code&gt;TAG&lt;/code&gt;, joined by a colon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run games:tic-tac-toe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When I list the containers running on my system, I see my game:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; docker ps -a
CONTAINER ID  IMAGE        COMMAND           CREATED       STATUS                 PORTS   NAMES
f8763546a856  ec616ed52b3b "/bin/tictactoe"  1 minute ago  Up 1 minute (healthy)          abundant_fun
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the container, players make a series of moves ending in a stalemate:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/bKu5H0DiSPM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Recall that the moves are saved in the container layer, but the game board and all of the rules are part of the image. What if I could change the &lt;em&gt;existing&lt;/em&gt; image used by a running container? Perhaps rewriting the Dockerfile and shifting the board to the right:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/-Bxe_-UyOVQ"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If the container used the changed image, moves in the leftmost column of the container layer would fall off the board, while three new spaces open up on the right! The game is no longer a stalemate! Now, Player O has two paths to victory courtesy of the repositioned game board in the new image, and Player X can block only one!&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/7LFvAltPOF8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;That demonstrates what &lt;em&gt;would&lt;/em&gt; happen if you &lt;em&gt;could&lt;/em&gt; change an existing image. But it does raise a question: what happens when you replace an image?&lt;/p&gt;

&lt;h2&gt;
  
  
  The  Repo
&lt;/h2&gt;

&lt;p&gt;Recall the original image was named &lt;code&gt;games:tic-tac-toe&lt;/code&gt;. If there were no containers using the image, Docker simply removes and replaces the image. But in the example above, a container &lt;em&gt;was&lt;/em&gt; using the "old" image. So, does Docker respond by removing the container? Does it crash or stop responding when its image is replaced? Fortunately not!&lt;/p&gt;

&lt;p&gt;In this case, Docker preserves the original image by un-tagging it—removing the friendly name—making the &lt;code&gt;games:tic-tac-toe&lt;/code&gt; tag available to the newly built image. Once untagged, the image no longer has a friendly name, which I'll see when I once again list the images on the system:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; docker images
REPOSITORY   TAG           IMAGE ID       CREATED       SIZE
games        tic-tac-toe   2fafb511dc00   1 hour ago    100KB
&amp;lt;none&amp;gt;       &amp;lt;none&amp;gt;        ec616ed52b3b   2 hours ago   100KB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One shows &lt;code&gt;&amp;lt;none&amp;gt;&lt;/code&gt; for the &lt;code&gt;REPOSITORY&lt;/code&gt; and &lt;code&gt;TAG&lt;/code&gt;. Look closely, and you'll see the &lt;code&gt;IMAGE ID&lt;/code&gt; matches the original image. By rebuilding the image, Docker untagged the old one but didn't delete it! Any containers that used the "old" image continue to work as before, without any change!&lt;/p&gt;

&lt;p&gt;If you see &lt;code&gt;&amp;lt;none&amp;gt;&lt;/code&gt; listed for an image repository and tag, it just means it was untagged or replaced while still in use by a running container.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>cloudnative</category>
    </item>
    <item>
      <title>Visual Docker: Images and Containers</title>
      <dc:creator>Oracle Sean  ♠️</dc:creator>
      <pubDate>Thu, 06 Apr 2023 11:49:24 +0000</pubDate>
      <link>https://dev.to/oraclesean/visual-docker-images-and-containers-48d9</link>
      <guid>https://dev.to/oraclesean/visual-docker-images-and-containers-48d9</guid>
      <description>&lt;h2&gt;
  
  
  Containers = Images + Trickery!
&lt;/h2&gt;

&lt;p&gt;Imagine a company that provides TTTaaS—Tic-Tac-Toe as a Service. The website is &lt;em&gt;the destination&lt;/em&gt; for Tic-Tac-Toe players around the globe! When people land on the home page and start a new game of Tic-Tac-Toe, they're starting a new Tic-Tac-Toe &lt;strong&gt;container&lt;/strong&gt; where they can enjoy a game with a friend, like this:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/SBHPgsxr8M8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Behind the scenes, the code that starts the container looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker start tic-tac-toe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Containers are platforms that deliver &lt;strong&gt;services&lt;/strong&gt;—in this case, a game. A game, &lt;em&gt;like an application&lt;/em&gt;, has rules and an environment where the activity takes place.&lt;/p&gt;

&lt;p&gt;But containers are &lt;em&gt;more&lt;/em&gt; than they appear to be!&lt;/p&gt;

&lt;h2&gt;
  
  
  More Than Meets the Eye!
&lt;/h2&gt;

&lt;p&gt;The container in the video above tricked you into thinking you watched two people play an ordinary game of Tic-Tac-Toe.&lt;/p&gt;

&lt;p&gt;You actually saw &lt;em&gt;two things&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You saw the &lt;strong&gt;container&lt;/strong&gt;, where the moves were made and persisted, but you also saw the Tic-Tac-Toe &lt;strong&gt;image&lt;/strong&gt;! But how could you see both things at once?&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;container&lt;/strong&gt; is really just a thin, transparent layer superimposed on top of the image. When it's peeled away, it reveals the image beneath:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/I-n2ZXMKGJw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;image&lt;/strong&gt; is the Tic-Tac-Toe board we see, plus some embedded metadata and instructions—the rules for playing the game.&lt;/p&gt;

&lt;p&gt;We &lt;strong&gt;run&lt;/strong&gt; an image to create a container. The single required argument of the &lt;code&gt;docker run&lt;/code&gt; command is the image name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run tic-tac-toe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running Images
&lt;/h2&gt;

&lt;p&gt;What happens behind the scenes when running a container?&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Prepare the Game
&lt;/h3&gt;

&lt;p&gt;First, Docker creates a new, empty layer for the container and arranges it over the image in a picture frame. In Docker, that picture frame is called a &lt;em&gt;union filesystem&lt;/em&gt; (known also as a merge or overlay filesystem). The picture frame keeps everything neatly aligned.&lt;/p&gt;

&lt;p&gt;Union filesystems, like picture frames, have three &lt;em&gt;layers&lt;/em&gt;, called &lt;strong&gt;lower&lt;/strong&gt;, &lt;strong&gt;upper&lt;/strong&gt;, and &lt;strong&gt;merge&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;image&lt;/strong&gt; is the &lt;strong&gt;lower layer&lt;/strong&gt;—the game board and rules.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;container&lt;/strong&gt; is the &lt;strong&gt;upper layer&lt;/strong&gt;—a thin, transparent sheet of glass or plastic that's initially empty.&lt;/li&gt;
&lt;li&gt;Your perception is the &lt;strong&gt;merge layer&lt;/strong&gt;, a combination of the image and anything extra drawn onto the protective container layer.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step 2: Start the Game
&lt;/h3&gt;

&lt;p&gt;Next, Docker starts the game and the players begin taking turns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Container Properties
&lt;/h2&gt;

&lt;p&gt;Container design is unique and allows them to do weird and wonderful things!&lt;/p&gt;

&lt;h3&gt;
  
  
  Every Game Uses the Same Image
&lt;/h3&gt;

&lt;p&gt;Multiple games of Tic-Tac-Toe that all share one image—not a copy—the exact same image!&lt;/p&gt;

&lt;p&gt;Activity in individual containers never reaches the parent image, so it safely delivers the lower layer for &lt;em&gt;every&lt;/em&gt; container, where the pre-made board and rules embedded mean every game is guaranteed to start and work identically!&lt;/p&gt;

&lt;h3&gt;
  
  
  Containers Persist State
&lt;/h3&gt;

&lt;p&gt;Stopping and restarting the game doesn't change the container layer, where moves—the game's &lt;strong&gt;state&lt;/strong&gt;—are saved (persisted).&lt;/p&gt;

&lt;h3&gt;
  
  
  Images Don't Change
&lt;/h3&gt;

&lt;p&gt;The thin container layer protects the image from changes. Getting "inside" the container really just means that you've reached the clear plastic sheet. The image below is protected and never changes. All of the gameplay happens in the container layer—never in the image. Since images are unreachable and can't change, we say that they're &lt;em&gt;stateless&lt;/em&gt; and &lt;em&gt;immutable&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Containers Start Quickly
&lt;/h3&gt;

&lt;p&gt;Whether it's a small and simple game, like Tic-Tac-Toe, or a big and complicated game like Chess, the time needed to start the game is the same—as long as it takes to build the picture frame that superimposes the thin, transparent container layer over the image.&lt;/p&gt;

&lt;h3&gt;
  
  
  Containers Achieve Greater Density
&lt;/h3&gt;

&lt;p&gt;A server's container capacity is &lt;em&gt;far higher&lt;/em&gt; than its comparable VM capacity.&lt;/p&gt;

&lt;p&gt;Let's say the rule book for Tic-Tac-Toe is 99 pages, and every game uses one additional page. Each VM requires 100 pages per game, meaning a host with space for 1,000 pages can support ten Tic-Tac-Toe VMs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;10 * (99 + 1) = 1,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By separating the rules and instruction book into a common image and saving moves in individual containers, the same machine supports &lt;em&gt;901 Tic-Tac-Toe containers&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;99 + (901 * 1) = 1,000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;What did we learn?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Images provide the playing surface and rules for games.&lt;/li&gt;
&lt;li&gt;Containers deliver games as services.&lt;/li&gt;
&lt;li&gt;Each container is a thin layer superimposed over the image.&lt;/li&gt;
&lt;li&gt;The layers are assembled in a union filesystem that works like a picture frame.&lt;/li&gt;
&lt;li&gt;Plays accumulate and persist in dedicated container layers.&lt;/li&gt;
&lt;li&gt;Every game shares the same board and rules and therefore behaves identically.&lt;/li&gt;
&lt;li&gt;A server hosting one image and many thin container layers supports more games, uses fewer resources, and reduces costs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the next installment, I'll explain immutability and why images can't change!&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
      <category>cloudnative</category>
    </item>
    <item>
      <title>Visual Docker: Introduction</title>
      <dc:creator>Oracle Sean  ♠️</dc:creator>
      <pubDate>Tue, 04 Apr 2023 20:02:32 +0000</pubDate>
      <link>https://dev.to/oraclesean/visual-docker-introduction-hho</link>
      <guid>https://dev.to/oraclesean/visual-docker-introduction-hho</guid>
      <description>&lt;h2&gt;
  
  
  “Containers are like lightweight virtual machines” is a poor analogy
&lt;/h2&gt;

&lt;p&gt;An effective analogy helps expose the parallels between something you already know or understand and the &lt;em&gt;new thing&lt;/em&gt; you're learning. The one that springs to mind for me is the comparison between flowing water and electric circuits. I learned it from my high school physics teacher way back in 1982, and to this day, I can't think of a circuit without picturing water moving through different diameter hoses, with sand or constrictions representing resistance and batteries delivering voltage replaced by pumps generating water pressure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9map9v9pb0j8qmfvh6p7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9map9v9pb0j8qmfvh6p7.png" alt="The Water Flow Analogy likens the flow of electricity in a circuit to the flow of water in hoses and through pumps and constrictions. It's an effective and accessible analog for imagining and anticipating how electrical systems behave." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It gives me a mental picture of a real, physical system that mimics the behavior of something abstract and helps me understand and even predict how the circuit works.&lt;/p&gt;

&lt;p&gt;Unfortunately, the Docker world doesn't have a good analogy for containers.&lt;/p&gt;

&lt;p&gt;When I give talks on Docker and ask people to describe containers, I hear two answers again and again:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Containers are control groups (cgroups) and namespaces&lt;/li&gt;
&lt;li&gt;Containers are like lightweight virtual machines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are problems with both of these. Saying containers are built from cgroups and namespaces isn't helpful unless you already understand cgroups and namespaces, and chances are that if you do, you probably already have a technical awareness of what containers are!&lt;/p&gt;

&lt;p&gt;Since most aren't familiar with these terms, I see most people leaning toward the "Containers are like lightweight virtual machines" comparison. But it has problems, too. It's just not a useful analogy because it doesn't advance our understanding of containers. Why not?&lt;/p&gt;

&lt;p&gt;If containers are like lightweight virtual machines, then… &lt;em&gt;what is a lightweight virtual machine?&lt;/em&gt; For that matter, &lt;em&gt;what's a virtual machine?&lt;/em&gt; Can you describe VMs in &lt;em&gt;non-technical&lt;/em&gt; terms that a &lt;em&gt;layperson&lt;/em&gt; can understand?&lt;/p&gt;

&lt;p&gt;Even if you and your audience understand what virtual machines are, what's this special &lt;em&gt;"lightweight"&lt;/em&gt; virtual machine? What makes it lightweight? How is it different from a regular virtual machine? Why not just, &lt;em&gt;"They're like virtual machines?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;An analogy bridges the unknown to the familiar, equating something new to another thing you have experience with or can imagine easily. And a good analogy should work to describe a broad set of behaviors.&lt;/p&gt;

&lt;p&gt;Everyone understands that kinking a hose reduces water flow and creates pressure behind it, but "containers are like lightweight virtual machines" doesn't describe &lt;em&gt;anything&lt;/em&gt; about containers. It doesn't explain statelessness or immutability. There's no parallel that clarifies the differences between images and containers or accounts for fast startup times.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Tic-Tac-Toe Analogy
&lt;/h2&gt;

&lt;p&gt;I developed the Tic-Tac-Toe analogy as a better way of visually understanding containers. It's entirely non-technical and describes everything from fast startup times and how containers accomplish high density; to abstract concepts like immutability, persistence, ephemeralness, state, and caching; and constructs and properties like tags, builds, Dockerfiles, layers, union filesystems, and more!&lt;/p&gt;

&lt;p&gt;I'll cover each of these in separate posts in this series, beginning with the difference and relationship between images and containers.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>containers</category>
    </item>
    <item>
      <title>I wasn't speeding, your honor...</title>
      <dc:creator>Oracle Sean  ♠️</dc:creator>
      <pubDate>Tue, 07 Jan 2020 00:27:12 +0000</pubDate>
      <link>https://dev.to/oraclesean/i-wasn-t-speeding-your-honor-2f92</link>
      <guid>https://dev.to/oraclesean/i-wasn-t-speeding-your-honor-2f92</guid>
      <description>&lt;p&gt;...I was using maximum hardware capabilities to take advantage of a more optimized execution plan, reducing highway concurrency.&lt;/p&gt;

&lt;p&gt;#jokes #database #humor&lt;/p&gt;

</description>
      <category>jokes</category>
    </item>
  </channel>
</rss>
