1. What Are We Building? (Explained Simply)
Every beginner understands Docker theoretical concepts but gets confused when building their first project.
So here is the easiest possible example:
👉 A tiny Node.js web server that prints: “Hello from Docker 🎉”
We will:
- Build the app
- Create Dockerfile
- Build Docker image
- Run container
- Map ports
- Use volume
- See logs
- And understand Docker’s full workflow
This one project will teach you how Docker actually works in real life.
2. Project Structure (Visual)
random-docker-project/
│
├── server.js
└── Dockerfile
Simple. Clean. Beginner-friendly.
3. Step 1 — Create the App (server.js)
Create a file named server.js:
const http = require("http");
const server = http.createServer((req, res) => {
res.end("Hello from Docker 🎉");
});
server.listen(3000, () => {
console.log("Server running at http://localhost:3000");
});
This is the easiest Node.js server ever.
4. Step 2 — Create the Dockerfile
(Everything explained clearly)
Create Dockerfile:
# 1. Start with Node image
FROM node:18
# 2. Create working folder inside container
WORKDIR /app
# 3. Copy project files
COPY . .
# 4. Start the server
CMD ["node", "server.js"]
Visual Breakdown:
FROM node:18 → Borrow Node runtime
WORKDIR /app → Like choosing your working desk
COPY . . → Move files into container
CMD [...] → Tell Docker what to run
This is your complete “recipe card”.
🛠️ 5. Step 3 — Build the Docker Image
Run:
docker build -t random-app .
Visual:
Dockerfile → Image called "random-app"
🚀 6. Step 4 — Run the Container
Run:
docker run -p 8080:3000 random-app
Visual Explanation:
8080 (your laptop) → 3000 (inside container)
Open browser:
http://localhost:8080
You will see:
**Hello from Docker **
Congratulations — you just containerized your first real app.
7. Bonus: Add a Volume (For Live Editing)
Let’s connect your real folder to the container:
docker run -p 8080:3000 \
-v $(pwd):/app \
random-app
Now:
- Change
server.js - Refresh browser
- Changes apply instantly
This shows how developers use Docker in real projects.
8. Visual Summary of the Entire Workflow
Your App (server.js)
↓
Dockerfile (instructions)
↓ docker build
Docker Image (package)
↓ docker run
Container (running app)
↓
Browser (Hello from Docker 🎉)
Once you understand this pipeline, Docker becomes EASY.
9. Why This Example Helps You Understand Docker Properly
✔ You saw how to build a real working app
✔ You created a Dockerfile
✔ You built your own Docker image
✔ You understood port mapping
✔ You used a volume
✔ You saw logs
This covers 90% of Docker knowledge beginners need.
**10. FAQ **
Q1. Why do we map ports like 8080:3000?
Because the app inside container runs on port 3000, but your computer listens on 8080.
Q2. Why do we need a Dockerfile?
So Docker knows how to package your app — like a recipe.
Q3. Can I run multiple containers from the same image?
Yes. The image is reusable.
Q4. Why do we use -v volume?
To keep your data/code outside the container, safe and editable.
Q5. What happens when I stop the container?
Container stops → image remains → your code remains. (Unless you delete everything manually.)
🏁 Final Words
This one small project teaches everything:
How Docker builds, runs, stores, maps, and serves your apps.
Docker looks complicated only until you build your first project. After that, you realize:
“It’s just a smart box running my app anywhere I want.”
This is exactly what Docker by Example is for — making Docker simple, visual, and practical.