DEV Community

Jakaria Masum
Jakaria Masum

Posted on

Docker Images Explained Simply

Why I Decided to Learn Docker

As a web developer, I kept hearing about Docker — a tool that everyone says is “a must-learn” for deployment, team collaboration, and DevOps. But at first, it felt like something only backend engineers or DevOps folks needed.

Turns out, that’s not true.

So today, I decided to dive in — and guess what? I created my first Docker image from scratch and ran it like magic!

Here’s what I learned — explained the way I wish someone told me earlier.


What Even Is Docker?

Imagine you're building a project that works perfectly on your machine — but when you hand it to your friend or deploy it to a server, everything breaks.
Different environments, missing dependencies, version mismatches…

Docker solves that. It lets you package your app with everything it needs — code, dependencies, runtime — into a neat box called a container.

Think of a Docker container as a zip file of your app that always runs the same — anywhere.


Docker Image vs Container

  • Image = The blueprint (like a cake recipe)
  • Container = The actual running app (like the cake made from that recipe)

Creating My First Docker Image (Step-by-Step)

I created a simple Node.js app, wrote a Dockerfile, and ran it using Docker. Here’s how:


1. My Project Structure

docker-practice/ │ ├── index.js └── Dockerfile └── package.json └── package-lock.json 
Enter fullscreen mode Exit fullscreen mode

2. index.js (Simple server)

import express from "express"; const app = express(); const PORT = process.env.PORT || 3000; app.use(express.json()); app.get("/", (req, res) => { res.send("Hello from Docker container!"); }); app.listen(PORT, () => { console.log(`Server is running on http://localhost:${PORT}`); }); 
Enter fullscreen mode Exit fullscreen mode

3. Dockerfile (The magic recipe)

# Use the official Node.js image as the base image FROM node:20 # Set the working directory inside the container # This is where the application code will be copied and run WORKDIR /app # Copy package.json and package-lock.json (if available) to the working directory # This allows Docker to cache the npm install step, speeding up builds when dependencies haven't changed COPY package*.json . # Install the application dependencies # This will install all the dependencies listed in package.json RUN npm install # Copy the rest of the application code to the working directory # This includes all source files, configuration files, etc. COPY . . # Expose the port that the application will run on # This is the port that will be accessible from outside the container EXPOSE 3000 # Define the command to run the application # This command will be executed when the container starts # It starts the Node.js application using npm CMD ["npm", "start"] 
Enter fullscreen mode Exit fullscreen mode

4. Build the Image

docker build -t my-node-app . 
Enter fullscreen mode Exit fullscreen mode

This tells Docker:

“Hey, here’s my Dockerfile. Create an image and call it my-node-app.”


5. Run the Container

docker run -p 3000:3000 my-node-app 
Enter fullscreen mode Exit fullscreen mode

Now open http://localhost:3000 — and boom!
You’ll see Hello from Docker container!


What I Learned

  • Docker makes your app environment portable and consistent
  • A Dockerfile is like a list of cooking instructions for your app
  • Docker containers are isolated environments that run your app anywhere

Things That Surprised Me

  • How easy it was to build and run a container
  • How fast Docker is (it felt like running a normal app)
  • How powerful it is for collaboration and deployment

Top comments (0)