<?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: taragurung</title>
    <description>The latest articles on DEV Community by taragurung (@taragurung).</description>
    <link>https://dev.to/taragurung</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%2F803791%2Fb20edb87-6f08-436e-9771-705cd1ffa00d.jpeg</url>
      <title>DEV Community: taragurung</title>
      <link>https://dev.to/taragurung</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/taragurung"/>
    <language>en</language>
    <item>
      <title>Creating container from docker image (Part-2)</title>
      <dc:creator>taragurung</dc:creator>
      <pubDate>Mon, 20 Jan 2025 17:16:15 +0000</pubDate>
      <link>https://dev.to/taragurung/creating-container-from-docker-image-part-2-4h15</link>
      <guid>https://dev.to/taragurung/creating-container-from-docker-image-part-2-4h15</guid>
      <description>&lt;p&gt;If you have read Part-1 we are clear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We need docker image to create docker container&lt;/li&gt;
&lt;li&gt;We can create our own image or use docker images made by others&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where do we find the images built by others:
&lt;/h2&gt;

&lt;p&gt;The place where docker images are stored is called Docker Registry. Few widely used docker registries are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Docker hub&lt;/li&gt;
&lt;li&gt;AWS ECR (AWS Managed Service)&lt;/li&gt;
&lt;li&gt;GCP container service (GCP Managed Service)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;_Here, we will learn to run docker container pulling pubic docker images from DockerHub _&lt;/strong&gt;(&lt;a href="https://hub.docker.com/" rel="noopener noreferrer"&gt;https://hub.docker.com/&lt;/a&gt;) for simplicity purpose. &lt;/p&gt;

&lt;h2&gt;
  
  
  From docker registry to docker container
&lt;/h2&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%2Fa9ks6y5m2g4hoqk506qg.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%2Fa9ks6y5m2g4hoqk506qg.PNG" alt="image-pull-and-run" width="737" height="347"&gt;&lt;/a&gt;&lt;em&gt;fig: How images are pulled and runs as docker container&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search for the docker images in DockerHub (hub.docker.com). Type the name of the image you are looking for. For example: nginx, choose the one that best fits your requirement&lt;/li&gt;
&lt;li&gt;Pull the image&lt;/li&gt;
&lt;li&gt;Run it. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;When running docker container if the image is not found it will automatically look for the image and pull&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker command to pull image
&lt;/h2&gt;

&lt;p&gt;This command will pull public docker image named as nginx from docker registry.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull nginx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you want to pull specific version of docker image then we pass it after image name as shown in example bellow, and its called as &lt;strong&gt;tag&lt;/strong&gt;. If no tag is provided then it will  use &lt;strong&gt;latest&lt;/strong&gt; as the default tag.  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker pull nginx:1.27.3-alpine&lt;/code&gt;&lt;br&gt;
All the available tags will be listed in docker registry&lt;/p&gt;
&lt;h2&gt;
  
  
  docker command to run docker container from pulled image
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;docker run -itd --name mynginx nginx&lt;/code&gt;&lt;br&gt;
Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;itd&lt;/strong&gt; refers to: interactive mode, terminal mode and detached mode. (more on this later)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mynginx&lt;/strong&gt; refers to name of the container passed after &lt;strong&gt;--name&lt;/strong&gt;argument&lt;/li&gt;
&lt;li&gt;nginx refers to the image name&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Few must know docker commands:
&lt;/h2&gt;

&lt;p&gt;Now, you are familiar with how to run docker containers from docker images but that's not enough. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Running a docker container&lt;/strong&gt;&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 -itd nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking running containers&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking locally available docker images&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker images
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Assigning ports&lt;/strong&gt;&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 -itd -p 8000:80 nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Getting inside docker container for debugging or similar to sshing into server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker exec -it &amp;lt;container-name / id &amp;gt; sh or bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Checking docker logs&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker logs &amp;lt;container-name / id&amp;gt; -f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Inspecting for getting detailed information about container&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker inspect &amp;lt;container-name / id &amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Stopping the container&lt;/strong&gt;&lt;br&gt;
stopping docker container when not required&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker stop &amp;lt;container-name/id&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We need docker image to create docker container.&lt;/li&gt;
&lt;li&gt;docker images are stored in registries. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>docker</category>
      <category>kubernetes</category>
      <category>devops</category>
    </item>
    <item>
      <title>Problem Docker solves, installation guide (Part-1)</title>
      <dc:creator>taragurung</dc:creator>
      <pubDate>Mon, 20 Jan 2025 16:11:14 +0000</pubDate>
      <link>https://dev.to/taragurung/learn-docker-kubernetes-with-me-what-problem-does-docker-solve-installation-guide-pt-1-1bb5</link>
      <guid>https://dev.to/taragurung/learn-docker-kubernetes-with-me-what-problem-does-docker-solve-installation-guide-pt-1-1bb5</guid>
      <description>&lt;p&gt;Docker is revolved around 2 major issues:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1- The Application that runs on my machine is not quite guaranteed to run on another machine.&lt;br&gt;
2- Setting up a new environment is a time-consuming process.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are numerous benefits of using docker but we will discuss that later. &lt;/p&gt;

&lt;p&gt;To understand Docker effectively, it's important to first explore the fundamentals of virtualization and containerization. However, before diving into those concepts, let’s get started by setting up Docker on your system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Virtualization and Containerization in next chapter&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up docker in Linux machine
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Installing with apt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release &amp;amp;&amp;amp; echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list &amp;gt; /dev/null
sudo apt-get update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Install the latest version&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Verify installation:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Official installation documentation here: &lt;a href="https://docs.docker.com/engine/install/ubuntu/" rel="noopener noreferrer"&gt;https://docs.docker.com/engine/install/ubuntu/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, I have shown how to do it on Ubuntu Server. Depending upon your Os type you can follow the official documentation guide. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up docker in Macos machine
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Visit this url &lt;a href="https://docs.docker.com/desktop/setup/install/mac-install/" rel="noopener noreferrer"&gt;https://docs.docker.com/desktop/setup/install/mac-install/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Choose the correct version for your processor (Apple Silicon or Intel). If you have m1 chip download from the button that says &lt;code&gt;Docker Desktop for Mac with Apple Silicon&lt;/code&gt; if not use another button to download.&lt;/li&gt;
&lt;li&gt;Open the downloaded .dmg file and install&lt;/li&gt;
&lt;li&gt;Open Docker from the Applications folder or Spotlight search.&lt;/li&gt;
&lt;li&gt;Grant necessary permissions if prompted.&lt;/li&gt;
&lt;li&gt;Sign in with your Docker Hub account or create one if you don’t have it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up docker in Windows machine
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Download Docker Desktop:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Visit the Docker Desktop for Windows page. &lt;a href="https://docs.docker.com/desktop/setup/install/windows-install/" rel="noopener noreferrer"&gt;https://docs.docker.com/desktop/setup/install/windows-install/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Download the installer, depending upon your Windows type. AMD or Arm &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. Install Docker Desktop:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Run the installer and follow the setup wizard.&lt;/li&gt;
&lt;li&gt;When prompted, ensure Use WSL 2 instead of Hyper-V is selected (if you're on Windows Home).&lt;/li&gt;
&lt;li&gt;Restart if necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Launch Docker Desktop:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open Docker Desktop from the Start Menu.&lt;/li&gt;
&lt;li&gt;Sign in with your Docker Hub account or create one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Back to the problem, how docker solves the issues of incompatibility:
&lt;/h2&gt;

&lt;p&gt;To make it easy to understandable let's put it like this. I drew one sketch and asked another guy to draw the same, he might be able to but will of course be hard for him to have an exact copy of mine. &lt;/p&gt;

&lt;p&gt;The solution could be,I will provide him sketch as a base image to follow and just ask to do photocopy of it instead of drawing it again which will solve the two problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now the duplicate sketch will be exact the same&lt;/li&gt;
&lt;li&gt;Secondly, it will save a lot of time for him. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have a similar concept in docker we create a base image first keeping all the application codes and dependencies which will then be used to create a docker container.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dockers Basic two concepts to understand:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Docker image:
&lt;/h3&gt;

&lt;p&gt;We need the docker image to run an application as docker container.&lt;br&gt;
It's a process of attaching all the codes and dependencies required by the application.&lt;br&gt;
We can either create our own docker images or use those pre-built by someone and publicly available. We will learn later how to create a docker images.&lt;/p&gt;

&lt;h3&gt;
  
  
  Docker container:
&lt;/h3&gt;

&lt;p&gt;We run a docker image which when runs is termed as docker container. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Final though:&lt;/strong&gt; we compact everything into docker image which can be transferred to any machine and is guaranteed to have the same codes and dependencies and run without any configuration hassle. &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>devops</category>
      <category>docker</category>
      <category>kubernetes</category>
    </item>
  </channel>
</rss>
