<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Untitled Publication]]></title><description><![CDATA[Untitled Publication]]></description><link>https://desmond3th.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 31 Aug 2026 19:13:42 GMT</lastBuildDate><atom:link href="https://desmond3th.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Simplifying Docker.]]></title><description><![CDATA[I know before learning or using any new technology, our first question often is why use it in the very first place.
Well, we need to understand how things were before Docker came into the picture and the problem it aimed to fix.
Before Docker
Virtual...]]></description><link>https://desmond3th.hashnode.dev/simplifying-docker</link><guid isPermaLink="true">https://desmond3th.hashnode.dev/simplifying-docker</guid><category><![CDATA[Docker]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[containers]]></category><dc:creator><![CDATA[Saurabh Kumar]]></dc:creator><pubDate>Sat, 20 Apr 2024 09:22:05 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1713604490758/532ce6a9-7d39-4911-91ec-8ade180757af.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>I know before learning or using any new technology, our first question often is why use it in the very first place.</p>
<p>Well, we need to understand how things were before Docker came into the picture and the problem it aimed to fix.</p>
<h3 id="heading-before-docker">Before Docker</h3>
<p>Virtual machines (VMs) were the primary solution for many application development and deployment needs. VMs offered a way to create isolated environments within a single physical server. However, provisioning multiple virtual machines, each with its operating system, could be resource-intensive and less efficient. The virtual machines also consume higher disk space as each VM is heavy. This is the exact problem that <strong>containers</strong> aim to solve.</p>
<h3 id="heading-containers">Containers</h3>
<p>Containers are not something new; they have existed for a long time. Think of a container as an isolated virtual environment for your application, but it's much lighter and faster than VMs. Containers use the same underlying operating system kernel, unlike VMs. A container includes your application and everything it needs to run, like code, settings, dependencies, and some parts of the OS. They run consistently across different environments, isolated from the rest of the system.</p>
<h3 id="heading-vms-amp-containers">VMs &amp; Containers</h3>
<p>It's not a choice between containers or virtual machines; it's often containers and virtual machines coexisting in large environments.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697916551066/aeb68f2c-a431-4684-81a6-1c331f41606c.png" alt class="image--center mx-auto" /></p>
<p>Containers are the best option for modern apps due to their portability and scalability, making them perfect for cloud-native solutions. Yet, VMs are better for hosting applications, offering strong isolation by allowing different operating systems and kernels to run on a single machine. Now, you might provision a virtual machine for hundreds or thousands of containers.</p>
<h3 id="heading-what-is-docker">What is Docker?</h3>
<p>Docker is a high-level tool that provides a user-friendly interface and powerful functionalities for creating, managing, and running containers. It helps in the process of setting up and working with containers, allowing users to package applications and their dependencies in a consistent, portable, and efficient manner. You don't need to spend hours setting the environment for your application. Just put your application's stuff inside a <strong>"Docker Container"</strong> and it's ready to run.</p>
<h3 id="heading-client-server-architecture-of-docker">Client-Server Architecture of Docker</h3>
<p>Yes, Docker uses a Client-Server architecture. The user interacts with the Docker Client with commands. The Client communicates with the Docker Daemon, which does all the tasks such as building and running them.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697917613222/62e03e65-eef9-403c-b590-6ee78b5f649c.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-some-docker-elements">Some Docker Elements</h3>
<ul>
<li><p><strong><mark>Docker Image</mark></strong></p>
<p>  Docker image is a template for creating a container, it is built using the instructions that are defined in a Dockerfile. They are designed in layers and each layer is immutable, meaning they do not change after they are built. This immutability ensures consistency in different environments.</p>
</li>
<li><p><strong><mark>Docker registries</mark></strong></p>
<p>  Docker registries are the centralized repo for Docker Images. One can choose between private or public (Docker Hub) registries according to your needs. Docker images are pushed to and pulled from these registries, allowing for easy distribution and sharing of containerized applications.</p>
</li>
<li><p><strong><mark>Dockerfile</mark></strong></p>
<p>  Dockerfile is like a blueprint for building a house. This file contains all the instructions and configuration to create an Image. It defines the instructions like base image, sets up the environment, installs software, copies files, and specifies commands to run.</p>
<p>  Here's a simple Dockerfile that prints "Hello, Docker!" when you run a container from it :</p>
<pre><code class="lang-yaml">  <span class="hljs-string">FROM</span> <span class="hljs-string">python</span>
  <span class="hljs-string">CMD</span> [<span class="hljs-string">"python"</span>, <span class="hljs-string">"-c"</span>, <span class="hljs-string">"print('Hello, Docker!')"</span>]
</code></pre>
</li>
</ul>
<h3 id="heading-workflow">Workflow</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697918564254/87d94862-f3d5-4f8a-931f-3d6a7c18bac7.png" alt /></p>
<p>A Dockerfile serves to create Docker Images. These Docker Images are like snapshots of your application. They are lightweight and portable. Once you've built a Docker Image, you can use it to create isolated instances called containers. Containers are where your application runs.</p>
<h3 id="heading-some-commands">Some commands</h3>
<pre><code class="lang-yaml"><span class="hljs-string">docker</span> <span class="hljs-string">pull</span> <span class="hljs-string">imageName</span> <span class="hljs-comment"># Pull an image</span>

<span class="hljs-string">docker</span> <span class="hljs-string">images</span> <span class="hljs-comment"># List Docker images</span>

<span class="hljs-string">docker</span> <span class="hljs-string">run</span> <span class="hljs-string">-it</span> <span class="hljs-string">imageName</span> <span class="hljs-comment"># Run a container interactively</span>

<span class="hljs-string">docker</span> <span class="hljs-string">run</span> <span class="hljs-string">-d</span> <span class="hljs-string">imageName</span> <span class="hljs-comment"># Run a container in detached mode (background)</span>

<span class="hljs-string">docker</span> <span class="hljs-string">ps</span> <span class="hljs-string">-a</span> <span class="hljs-comment"># List all containers (including stopped ones)</span>

<span class="hljs-string">docker</span> <span class="hljs-string">stop</span> <span class="hljs-string">containerID</span> <span class="hljs-string">or</span> <span class="hljs-string">ContainerName</span> <span class="hljs-comment"># Stop a container</span>

<span class="hljs-string">docker</span> <span class="hljs-string">start</span> <span class="hljs-string">containerID</span> <span class="hljs-string">or</span> <span class="hljs-string">ContainerName</span> <span class="hljs-comment"># Start a container</span>

<span class="hljs-string">docker</span> <span class="hljs-string">rm</span> <span class="hljs-string">containerID</span> <span class="hljs-string">or</span> <span class="hljs-string">ContainerName</span> <span class="hljs-comment"># Remove a container</span>

<span class="hljs-string">docker</span> <span class="hljs-string">rmi</span> <span class="hljs-string">imageName</span>  <span class="hljs-comment"># Remove an image</span>

<span class="hljs-string">docker</span> <span class="hljs-string">push</span> <span class="hljs-string">imageName</span>  <span class="hljs-comment"># Push an image to a registry </span>

<span class="hljs-string">docker</span> <span class="hljs-string">logs</span> <span class="hljs-string">containerID</span> <span class="hljs-string">or</span> <span class="hljs-string">ContainerName</span> <span class="hljs-comment"># View logs of a running container</span>

<span class="hljs-string">docker</span> <span class="hljs-string">exec</span> <span class="hljs-string">-it</span> <span class="hljs-string">containerID</span> <span class="hljs-string">or</span> <span class="hljs-string">ContainerName</span> <span class="hljs-comment"># Execute a command in a running container</span>
</code></pre>
<h3 id="heading-hands-on">Hands-on</h3>
<p>Let's try to pull an image from <a target="_blank" href="https://hub.docker.com/">Docker Hub</a> which is a public registry and run a container. Make sure you've configured Docker into your system and Docker daemon is running. For assistance: <a target="_blank" href="https://docs.docker.com/get-docker/">Get Docker</a></p>
<ul>
<li><p>We'll be using the python image here :</p>
<pre><code class="lang-yaml">  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">pull</span> <span class="hljs-string">python</span>
  <span class="hljs-attr">Using default tag:</span> <span class="hljs-string">latest</span>
  <span class="hljs-attr">latest:</span> <span class="hljs-string">Pulling</span> <span class="hljs-string">from</span> <span class="hljs-string">library/python</span>
  <span class="hljs-attr">0a9573503463:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">complete</span>
  <span class="hljs-attr">1ccc26d841b4:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">complete</span>
  <span class="hljs-attr">7c45daddd450:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">complete</span>
  <span class="hljs-attr">0952bd8ba4ec:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">complete</span>
  <span class="hljs-attr">53f1aa318bc2:</span> <span class="hljs-string">Pull</span> <span class="hljs-string">complete</span>
  <span class="hljs-attr">Digest:</span> <span class="hljs-string">sha256:2586dd7abe015eeb6673bc66d18f0a628a997c293b41268bc981e826bc0b5a92</span>
  <span class="hljs-attr">Status:</span> <span class="hljs-string">Downloaded</span> <span class="hljs-string">newer</span> <span class="hljs-string">image</span> <span class="hljs-string">for</span> <span class="hljs-string">python:latest</span>
  <span class="hljs-string">docker.io/library/python:latest</span>

  <span class="hljs-string">What's</span> <span class="hljs-string">Next?</span>
    <span class="hljs-string">View</span> <span class="hljs-string">summary</span> <span class="hljs-string">of</span> <span class="hljs-string">image</span> <span class="hljs-string">vulnerabilities</span> <span class="hljs-string">and</span> <span class="hljs-string">recommendations</span> <span class="hljs-string">→</span> <span class="hljs-string">docker</span> <span class="hljs-string">scout</span> <span class="hljs-string">quickview</span> <span class="hljs-string">python</span>
</code></pre>
<p>  By default docker pulls the latest version of Python, you can specify the tag implicitly. e.g. <code>docker pull python:3.11</code></p>
</li>
<li><p>Now that you have an image in your system you can create a container from it :</p>
<pre><code class="lang-yaml">  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">image</span> <span class="hljs-string">ls</span>
  <span class="hljs-string">REPOSITORY</span>   <span class="hljs-string">TAG</span>       <span class="hljs-string">IMAGE</span> <span class="hljs-string">ID</span>       <span class="hljs-string">CREATED</span>      <span class="hljs-string">SIZE</span>
  <span class="hljs-string">python</span>       <span class="hljs-string">latest</span>    <span class="hljs-string">17e65561fd2c</span>   <span class="hljs-number">5</span> <span class="hljs-string">days</span> <span class="hljs-string">ago</span>   <span class="hljs-number">1.</span><span class="hljs-string">02GB</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">run</span> <span class="hljs-string">-it</span> <span class="hljs-string">python</span>
  <span class="hljs-string">Python</span> <span class="hljs-number">3.12</span><span class="hljs-number">.0</span> <span class="hljs-string">(main,</span> <span class="hljs-string">Apr</span> <span class="hljs-number">20</span> <span class="hljs-number">2024</span><span class="hljs-string">,</span> <span class="hljs-number">09</span><span class="hljs-string">:45:59)</span> [<span class="hljs-string">GCC</span> <span class="hljs-number">12.2</span><span class="hljs-number">.0</span>] <span class="hljs-string">on</span> <span class="hljs-string">linux</span>
  <span class="hljs-string">Type</span> <span class="hljs-string">"help"</span><span class="hljs-string">,</span> <span class="hljs-string">"copyright"</span><span class="hljs-string">,</span> <span class="hljs-string">"credits"</span> <span class="hljs-string">or</span> <span class="hljs-string">"license"</span> <span class="hljs-string">for</span> <span class="hljs-string">more</span> <span class="hljs-string">information.</span>
  <span class="hljs-string">&gt;&gt;&gt;</span> <span class="hljs-string">print('Hello,</span> <span class="hljs-string">world!')</span>
  <span class="hljs-string">Hello,</span> <span class="hljs-string">world!</span>
  <span class="hljs-string">&gt;&gt;&gt;</span> <span class="hljs-string">(3+7)</span>
  <span class="hljs-number">10</span>
  <span class="hljs-string">&gt;&gt;&gt;exit()</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">run</span> <span class="hljs-string">-d</span> <span class="hljs-string">python</span>
  <span class="hljs-string">da8371465e74e7cdc6a29578c67f4fdf973f0e9e88d723f70ceeadc4276ed416</span>
</code></pre>
<p>  <code>-it</code> allows us to interact with the container's shell or application in an interactive and user-friendly way.</p>
<p>  <code>-d</code> runs the container in detached mode.</p>
</li>
<li><p>Our purpose is achieved, so let's just remove the container and image from our system :</p>
<pre><code class="lang-yaml">  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">ps</span> <span class="hljs-string">-a</span>
  <span class="hljs-string">CONTAINER</span> <span class="hljs-string">ID</span>   <span class="hljs-string">IMAGE</span>     <span class="hljs-string">COMMAND</span>     <span class="hljs-string">CREATED</span>         <span class="hljs-string">STATUS</span>                     <span class="hljs-string">PORTS</span>     <span class="hljs-string">NAMES</span>
  <span class="hljs-string">da8371465e74</span>   <span class="hljs-string">python</span>    <span class="hljs-string">"python3"</span>   <span class="hljs-number">2</span> <span class="hljs-string">minutes</span> <span class="hljs-string">ago</span>   <span class="hljs-string">Exited</span> <span class="hljs-string">(0)</span> <span class="hljs-number">2</span> <span class="hljs-string">minutes</span> <span class="hljs-string">ago</span>             <span class="hljs-string">unruffled_gagarin</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">rm</span> <span class="hljs-string">da83</span>
  <span class="hljs-string">da83</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">ps</span> <span class="hljs-string">-a</span>
  <span class="hljs-string">CONTAINER</span> <span class="hljs-string">ID</span>   <span class="hljs-string">IMAGE</span>     <span class="hljs-string">COMMAND</span>   <span class="hljs-string">CREATED</span>   <span class="hljs-string">STATUS</span>    <span class="hljs-string">PORTS</span>     <span class="hljs-string">NAMES</span>
  <span class="hljs-string">root@MSI:~#</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">image</span> <span class="hljs-string">ls</span>
  <span class="hljs-string">REPOSITORY</span>   <span class="hljs-string">TAG</span>       <span class="hljs-string">IMAGE</span> <span class="hljs-string">ID</span>       <span class="hljs-string">CREATED</span>      <span class="hljs-string">SIZE</span>
  <span class="hljs-string">python</span>       <span class="hljs-string">latest</span>    <span class="hljs-string">17e65561fd2c</span>   <span class="hljs-number">5</span> <span class="hljs-string">days</span> <span class="hljs-string">ago</span>   <span class="hljs-number">1.</span><span class="hljs-string">02GB</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">rmi</span> <span class="hljs-string">python</span>
  <span class="hljs-attr">Untagged:</span> <span class="hljs-string">python:latest</span>
  <span class="hljs-attr">Untagged:</span> <span class="hljs-string">python@sha256:2586dd7abe015eeb6673bc66d18f0a628a997c293b41268bc981e826bc0b5a92</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:17e65561fd2c7ecae6297c2cc049960607ff94f92f6a1ca3857f94569fc9c199</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:781e8bd079dcc84a458a8f4f3a150194c7d4d97e99f46c969a5f021443245582</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:fe26881c5fffddca7e97ebdd52578444af7a9c2b490ba91b5d793de4d8c3c984</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:75a8404e2d8b812db31af6bafa0c0cb4c8deaf763ab5134484213933def00b09</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:3a78d30473881be3a54a8b6a11de5da7ac2dd645c813dcb7331527a30e50a993</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:354f4b6949596277291588a6a2b924144fa72edbc21ff3c12e168187e233fd0d</span>
  <span class="hljs-attr">Deleted:</span> <span class="hljs-string">sha256:2fa37f2ee66efbd308b9b91bce81c262f5e6ab6c3bf8056632afc60cc602785c</span>
  <span class="hljs-string">root@MSI:~#</span>
  <span class="hljs-string">root@MSI:~#</span> <span class="hljs-string">docker</span> <span class="hljs-string">image</span> <span class="hljs-string">ls</span>
  <span class="hljs-string">REPOSITORY</span>   <span class="hljs-string">TAG</span>       <span class="hljs-string">IMAGE</span> <span class="hljs-string">ID</span>   <span class="hljs-string">CREATED</span>   <span class="hljs-string">SIZE</span>
  <span class="hljs-string">root@MSI:~#</span>
</code></pre>
</li>
</ul>
<p>That's it. This is all you need to know to start with Docker. Remember, there are many more advanced features in Docker, start by experimenting with containers and getting hands-on with Docker.</p>
]]></content:encoded></item></channel></rss>