<?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>Forem: Angelo Costa</title>
    <description>The latest articles on Forem by Angelo Costa (@ang-costa-neto).</description>
    <link>https://forem.com/ang-costa-neto</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%2F1881478%2Fb6205ca3-befa-4407-a9e7-97887b5f6a15.jpeg</url>
      <title>Forem: Angelo Costa</title>
      <link>https://forem.com/ang-costa-neto</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ang-costa-neto"/>
    <language>en</language>
    <item>
      <title>Differences Between `var`, `let`, and `const` in JavaScript: A Simple Explanation</title>
      <dc:creator>Angelo Costa</dc:creator>
      <pubDate>Tue, 03 Sep 2024 01:00:35 +0000</pubDate>
      <link>https://forem.com/ang-costa-neto/differences-between-var-let-and-const-in-javascript-a-simple-explanation-3b59</link>
      <guid>https://forem.com/ang-costa-neto/differences-between-var-let-and-const-in-javascript-a-simple-explanation-3b59</guid>
      <description>&lt;p&gt;Imagine you're organizing your home. Each type of variable in JavaScript – &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt; – works like different kinds of spaces where you can store your things. Let's see how this fits with everyday items and code examples to make it even clearer!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;code&gt;var&lt;/code&gt; – The Messy Drawer
&lt;/h2&gt;

&lt;p&gt;Think of &lt;code&gt;var&lt;/code&gt; as that messy kitchen drawer filled with different things, a bit disorganized. You can put anything in there, and it's always accessible to you no matter where you are in the kitchen.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Accessible Anywhere in the Kitchen&lt;/strong&gt;: It doesn’t matter if you’re near the sink or the stove; you can always open that drawer and grab what’s inside.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Messy with Your Stuff&lt;/strong&gt;: If you put something in the drawer and then try to put something else with the same name, everything gets mixed up and works, but it can get confusing.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example of var&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mug&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints "Mug"&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Plate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Allows redeclaration&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Now prints "Plate"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Real-Life Example&lt;/strong&gt;: You put a pair of socks in the drawer, but then forget and put another pair of the same kind. The socks get mixed up, and you can't tell which pair is which.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtsk3m5lyj191pd4hh9v.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvtsk3m5lyj191pd4hh9v.jpeg" alt="messy drawer" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;code&gt;let&lt;/code&gt; – The Organized Toolbox
&lt;/h2&gt;

&lt;p&gt;Now, think of &lt;code&gt;let&lt;/code&gt; as a well-organized toolbox. The tools are there, but you can only access them when you open the toolbox. They are stored in a specific place, and you need to open the right toolbox to find them.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Accessible Only in the Toolbox&lt;/strong&gt;: The tools stay neatly in the toolbox, and you can only use them when you open it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better Organization&lt;/strong&gt;: If you try to put a screwdriver and then another screwdriver of the same type in the same toolbox, it won’t let you, as each tool has its own place.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example of let&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Screwdriver&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints "Screwdriver"&lt;/span&gt;

&lt;span class="nx"&gt;tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hammer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Can reassign the value&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Now prints "Hammer"&lt;/span&gt;

&lt;span class="c1"&gt;// let tool = "Hammer"; // This would cause an error, as you cannot redeclare&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Real-Life Example&lt;/strong&gt;: If you are assembling furniture, the screwdriver only appears when you open the toolbox, and it's put back when you close it. You can’t access the tool without opening the toolbox first.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3010cjzvzec8rbepqji2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3010cjzvzec8rbepqji2.jpeg" alt="Well-organized toolbox" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;code&gt;const&lt;/code&gt; – The Locked Safe
&lt;/h2&gt;

&lt;p&gt;Think of &lt;code&gt;const&lt;/code&gt; as a safe. Once you put something inside, it stays locked and can’t be changed. You can rearrange things inside the safe, like rearranging coins, but the safe itself stays locked with what you initially put in it.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Locked Forever&lt;/strong&gt;: When you put something in the safe, like treasures, you can rearrange the coins inside, but you can’t change the fact that you put coins in the safe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Protection Against Changes&lt;/strong&gt;: If you try to replace the treasures with something else, the safe simply won’t allow it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Example of const&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;safe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Jewels&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;safe&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints "Jewels"&lt;/span&gt;

&lt;span class="c1"&gt;// safe = "Money"; // This would cause an error, as you cannot reassign const&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;coins&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;coins&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// This is allowed&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;coins&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Prints [1, 2, 3, 4]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Real-Life Example&lt;/strong&gt;: Imagine you put jewels in the safe. You can rearrange the jewels, but you can’t change the fact that the safe’s purpose is to hold those jewels.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5m7d0cvp6o132gj98ozg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5m7d0cvp6o132gj98ozg.jpeg" alt="safe locked" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing Everything Together
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;var&lt;/code&gt; is like that messy drawer: You can put anything in there, and it's always accessible, but be careful – things can get mixed up easily!

&lt;ul&gt;
&lt;li&gt;Example: Declare the same variable multiple times without error.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; is like an organized toolbox: Tools are accessible only when you open the toolbox, keeping everything more organized.

&lt;ul&gt;
&lt;li&gt;Example: let variables can be reassigned but not redeclared.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;
&lt;code&gt;const&lt;/code&gt; is like a locked safe: Once you store something there, it can’t be replaced, but you can modify the contents.

&lt;ul&gt;
&lt;li&gt;Example: You cannot change a const variable, but you can modify items in an array stored in it.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now, whenever you're coding, think of these variables as different ways to organize your home. Use &lt;code&gt;let&lt;/code&gt; for situations where things might change, and &lt;code&gt;const&lt;/code&gt; for values that need to be protected. Avoid &lt;code&gt;var&lt;/code&gt; when possible – it's useful but can be confusing, like a messy drawer!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a93ik46qwkuhylfkpav.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7a93ik46qwkuhylfkpav.jpeg" alt="Organized room" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Docker: A Simple Introduction with Legos</title>
      <dc:creator>Angelo Costa</dc:creator>
      <pubDate>Sun, 04 Aug 2024 15:01:26 +0000</pubDate>
      <link>https://forem.com/ang-costa-neto/docker-a-simple-introduction-with-legos-40ki</link>
      <guid>https://forem.com/ang-costa-neto/docker-a-simple-introduction-with-legos-40ki</guid>
      <description>&lt;p&gt;Need help to understand how to start with docker? And has difficulty to understand all the terms and steps for building images or runing application? In bellow there is a little explanation using LEGOS!!!!&lt;/p&gt;

&lt;h2&gt;
  
  
  Docker: A Simple Introduction with Legos
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is Docker?
&lt;/h3&gt;

&lt;p&gt;Imagine you are building a model with Legos. Each Lego piece represents an important part of your model. Docker is like a box of Legos that organizes all these pieces so you can build your models (applications) quickly and easily.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use Docker?
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Consistency&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;With Docker, it's like always having the same Lego pieces no matter where you are. Whether you're in your room, at a friend's house, or at a park, your Lego pieces will always be the same, ensuring your model works the same way everywhere.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Portability&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Docker containers are like Lego boxes you can take anywhere. This means you can build and run your applications on any computer or server without worrying if the pieces will fit.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. &lt;strong&gt;Resource Efficiency&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Instead of having several large and heavy boxes (virtual machines), Docker allows you to use small and lightweight boxes (containers), which take up less space and are easier to carry.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. &lt;strong&gt;Ease of Development&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Docker makes building your models easy. You can organize your Lego pieces quickly and start building without wasting time looking for the right piece.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvx7m6ja3nxyg3swf6o4p.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvx7m6ja3nxyg3swf6o4p.jpeg" alt="Docker in shape of pieces of lego on top of notebook" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do We Need to Build an Image?
&lt;/h3&gt;

&lt;p&gt;Building an image is like assembling your Lego model so it's ready to use. Before you can start playing with it or showing it to your friends, you need to make sure all the pieces are in the right place and the model is complete. Building a Docker image ensures that your application is fully prepared to run.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Get Started with Docker
&lt;/h3&gt;

&lt;h4&gt;
  
  
  1. &lt;strong&gt;Installing Docker&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;First, you need to install Docker. You can find installation instructions &lt;a href="https://docs.docker.com/get-docker/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. &lt;strong&gt;Creating Your First Container&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Let's create a Lego box (container) for a simple Node.js application.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a file called &lt;code&gt;Dockerfile&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# Use the Node.js image&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; node:14&lt;/span&gt;

&lt;span class="c"&gt;# Create a working directory&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# Copy the package.json file and install dependencies&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; package.json .&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Copy the application code&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; . .&lt;/span&gt;

&lt;span class="c"&gt;# Expose the application port&lt;/span&gt;
&lt;span class="k"&gt;EXPOSE&lt;/span&gt;&lt;span class="s"&gt; 3000&lt;/span&gt;

&lt;span class="c"&gt;# Command to run the application&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["node", "index.js"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Build the Docker image&lt;/strong&gt;:&lt;br&gt;
Open the terminal and run:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; my-node-app &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here, Docker is assembling the Lego model. It pulls the Node.js base image, creates the working directory, installs dependencies, and copies the application code. At the end, you have a Docker image called &lt;code&gt;my-node-app&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Run the container&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-p&lt;/span&gt; 3000:3000 my-node-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is like taking the ready Lego model out of the box and starting to play with it. Docker creates a container from the &lt;code&gt;my-node-app&lt;/code&gt; image and runs the application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop everything!!!!!
&lt;/h2&gt;

&lt;p&gt;This is a lot of information right? But why we use the step above???&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi6i347icjr8cqitk5p6t.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi6i347icjr8cqitk5p6t.jpeg" alt="Lego person thinking" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  I will explain little bit
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Why Do We Need to Build an Image?
&lt;/h4&gt;

&lt;p&gt;Building an image is like assembling your Lego model so it's ready to use. Before you can start playing with it or showing it to your friends, you need to make sure all the pieces are in the right place and the model is complete. Building a Docker image ensures that your application is fully prepared to run.&lt;/p&gt;

&lt;h5&gt;
  
  
  Understanding the Build Process
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Organize the Pieces:&lt;/strong&gt;&lt;br&gt;
When you create a &lt;code&gt;Dockerfile&lt;/code&gt;, you are telling Docker which pieces (dependencies, libraries, code) you need to assemble your model (application).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Assemble the Model:&lt;/strong&gt;&lt;br&gt;
By running the &lt;code&gt;docker build&lt;/code&gt; command, Docker reads the &lt;code&gt;Dockerfile&lt;/code&gt; and follows the instructions to assemble the model. This includes pulling the base image (like grabbing a base Lego set), adding your dependencies (like getting specific Lego pieces), and copying your application code (like putting the pieces in the right place).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create the Box:&lt;/strong&gt;&lt;br&gt;
The result of the build process is a Docker image, which is like a box of assembled Lego ready to use. This image contains everything your application needs to run.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the Ready Model:&lt;/strong&gt;&lt;br&gt;
When you run a container from this image, it’s like taking the ready Lego model out of the box and starting to play with it. Everything is already set up and in place, so you can start using your application immediately.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguytzwgb9qbmq2zm0c2d.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fguytzwgb9qbmq2zm0c2d.jpeg" alt="Lego person with pieces lego behind" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Using Docker Compose&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Docker Compose is like a set of instructions for building a large model with several Lego boxes (containers). Let's create an example with a web application and a database.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a file called &lt;code&gt;docker-compose.yml&lt;/code&gt;&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3.9'&lt;/span&gt;
&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;web&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;my-node-app&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3000:3000"&lt;/span&gt;
  &lt;span class="na"&gt;db&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres:13&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;user&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;password&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;mydb&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Start the services&lt;/strong&gt;:&lt;br&gt;
Run in the terminal:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5a1kmm9jerkwaba5l6e.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5a1kmm9jerkwaba5l6e.jpeg" alt="Lego girl reading instruction to create" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Docker is like an amazing Lego box that makes it easy to build, transport, and run your applications. It ensures that your pieces (application components) always fit and work anywhere. Building a Docker image is essential because it prepares everything your application needs to run smoothly. Try Docker and see how it can transform the way you develop your applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvc2ilek56gi71rl3wiuu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvc2ilek56gi71rl3wiuu.jpeg" alt="Lego person saying good bye" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;All images was generated using AI&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>docker</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
