<?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: dev dev</title>
    <description>The latest articles on DEV Community by dev dev (@dev_dev_9fd9e2e8a5dbc85a6).</description>
    <link>https://dev.to/dev_dev_9fd9e2e8a5dbc85a6</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%2F3485081%2F6a25b233-0111-45be-bf53-a6b27f11236a.png</url>
      <title>DEV Community: dev dev</title>
      <link>https://dev.to/dev_dev_9fd9e2e8a5dbc85a6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dev_dev_9fd9e2e8a5dbc85a6"/>
    <language>en</language>
    <item>
      <title>🚀 Beginner’s Guide: Dockerize an App and Push It to Docker Hub</title>
      <dc:creator>dev dev</dc:creator>
      <pubDate>Sun, 14 Dec 2025 16:31:24 +0000</pubDate>
      <link>https://dev.to/dev_dev_9fd9e2e8a5dbc85a6/beginners-guide-dockerize-an-app-and-push-it-to-docker-hub-4m6j</link>
      <guid>https://dev.to/dev_dev_9fd9e2e8a5dbc85a6/beginners-guide-dockerize-an-app-and-push-it-to-docker-hub-4m6j</guid>
      <description>&lt;h5&gt;
  
  
  If you’re new to Docker and want a hands-on, practical example, this guide is for you.
&lt;/h5&gt;

&lt;h2&gt;
  
  
  🐳 What Is Docker?
&lt;/h2&gt;

&lt;p&gt;Docker is a tool that allows you to package an application and everything it needs to run (code, dependencies, libraries, and configuration) into a single unit called a container.&lt;/p&gt;

&lt;p&gt;Think of a container like a box 📦:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside the box: your app + Node.js + all dependencies&lt;/li&gt;
&lt;li&gt;Outside the box: any machine (laptop, server, cloud)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If Docker is installed, the app will run the same way everywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤔 Why Do We Use Docker?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Before Docker, developers often heard this problem:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;❌ “It works on my machine, but not on yours!”&lt;/p&gt;

&lt;p&gt;Docker solves this by creating consistent environments.&lt;/p&gt;

&lt;p&gt;✅ 1. Consistency Across Environments With Docker:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Same app runs on &lt;strong&gt;&lt;em&gt;local machine&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Same app runs on &lt;strong&gt;&lt;em&gt;testing&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Same app runs on &lt;strong&gt;&lt;em&gt;production&lt;/em&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No environment mismatch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this post, we will:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Clone a sample app from GitHub&lt;/li&gt;
&lt;li&gt;Understand the project structure&lt;/li&gt;
&lt;li&gt;Create a Dockerfile and .dockerignore&lt;/li&gt;
&lt;li&gt;Build and run Docker images locally&lt;/li&gt;
&lt;li&gt;Push the image to Docker Hub&lt;/li&gt;
&lt;li&gt;Pull the image from Docker Hub and run it&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;🧰 Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before we start, make sure you have:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Git installed&lt;/li&gt;
&lt;li&gt;Docker installed and running&lt;/li&gt;
&lt;li&gt;A Docker Hub account (free)&lt;/li&gt;
&lt;/ul&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git -v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify Docker installation:&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;h3&gt;
  
  
  📦 Step 1: Clone the GitHub Repository
&lt;/h3&gt;

&lt;p&gt;We’ll use Docker’s official getting-started app, which is perfect for beginners.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/docker/getting-started-app.git
cd getting-started-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple Node.js application that we’ll containerize.&lt;/p&gt;

&lt;h3&gt;
  
  
  📁 Step 2: Understand the Project Structure
&lt;/h3&gt;

&lt;p&gt;Inside the project, you’ll see files like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;getting-started-app/
├── spec/
├── src/
├── package.json
├── package-lock.json
└── README.md
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a Node.js application.&lt;br&gt;
To run it inside a container, we need a Dockerfile.&lt;/p&gt;
&lt;h3&gt;
  
  
  🐳 Step 3: Create a Dockerfile and .dockerignore
&lt;/h3&gt;
&lt;h4&gt;
  
  
  📄 Create a Dockerfile
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch Dockerfile
# or
code Dockerfile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Add the following content:
&lt;/h4&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%2Fuupwc69oioi0gavq16nn.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%2Fuupwc69oioi0gavq16nn.png" alt="docker file code" width="800" height="716"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;📄 Create a .dockerignore File&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch .dockerignore
#or
code .dockerignore
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add the following:
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;node_modules&lt;br&gt;
npm-debug.log&lt;br&gt;
Dockerfile&lt;br&gt;
.git&lt;br&gt;
.gitignore&lt;/code&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  ✅ Why .dockerignore is important:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Prevents unnecessary files from being copied&lt;/li&gt;
&lt;li&gt;Reduces image size&lt;/li&gt;
&lt;li&gt;Speeds up Docker builds&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  🏗️ Step 4: Build the Docker Image Locally
&lt;/h3&gt;

&lt;p&gt;Build the Docker image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t getting-started-app .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify the image:&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;h3&gt;
  
  
  ▶️ Step 5: Run the Docker Image Locally
&lt;/h3&gt;

&lt;p&gt;Run the container:&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 -d -p 3000:3000 getting-started-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your browser:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Frpdxxg188tlg2bw9jdtd.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%2Frpdxxg188tlg2bw9jdtd.png" alt="Out Put PNG" width="800" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🎉 Your app is running inside a Docker container!&lt;/p&gt;

&lt;h3&gt;
  
  
  🔐 Step 6: Login to Docker Hub
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;Enter your Docker Hub credentials.&lt;/p&gt;

&lt;h3&gt;
  
  
  🏷️ Step 7: Tag the Docker Image
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker tag getting-started-app your-dockerhub-username/getting-started-app:latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ☁️ Step 8: Push the Image to Docker Hub
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker push your-dockerhub-username/getting-started-app:latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your image is now available on Docker Hub 🚀&lt;/p&gt;

&lt;h3&gt;
  
  
  📥 Step 9: Pull the Image from Docker Hub
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker pull your-dockerhub-username/getting-started-app:latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ▶️ Step 10: Run the Image Pulled from Docker Hub
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -p 3000:3000 your-dockerhub-username/getting-started-app:latest

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit: &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✅ The app is now running from Docker Hub.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
