DEV Community

Cover image for Docker Explained: A Beginner-Friendly Introduction to Containerization (2025–2026)
MUKHIL S
MUKHIL S

Posted on

Docker Explained: A Beginner-Friendly Introduction to Containerization (2025–2026)

🐳 Docker for Absolute Beginners (2026) – Theory First, Then Hands-On

Hi everyone πŸ‘‹
If you've heard:

"Just dockerize it."

…and felt confused β€” this post is for you.

We’ll start with clear theory (mental model first)
Then move to hands-on practical commands

By the end, Docker will feel simple.


🧠 PART 1 – Understand Docker BEFORE Typing Commands

🚨 The Big Problem Docker Solves

Before Docker:

  • You write code
  • It depends on exact versions
  • Your laptop works
  • Production crashes
  • Your friend’s system fails

Result:

"But it works on my machine 😭"

Docker solves this.

Docker packages:

  • Your app
  • Runtime (Node, Python, Java)
  • Libraries
  • System dependencies
  • Configuration

Into a standard container that runs the same everywhere.


πŸ“¦ The Core Idea: Image vs Container

πŸ–Ό Docker Image vs πŸ“¦ Docker Container

Image

Image

Image

Concept Analogy Running? Changeable? Purpose
Image Recipe / Blueprint ❌ No ❌ Immutable Template
Container Cooked food / Running car βœ… Yes ⚠ Temporary Live app

Simple Programming Analogy:

  • Image = Class
  • Container = Object

You create many containers from one image.


🧱 How Docker Images Work (Layers)

Docker images are built in layers.

Example layers:

  1. Base OS (Ubuntu / Alpine)
  2. Install packages
  3. Install runtime (Node/Python)
  4. Copy app code
  5. Set startup command

Each step creates a new layer.

Why this is powerful:

  • Layers are cached
  • If only your code changes β†’ only last layer rebuilds
  • Faster builds
  • Less storage usage

When you run a container:

All image layers (read-only)

  • One small writable layer on top

Delete container β†’ writable layer disappears.

Unless you use Volumes (we’ll see later).


🚒 Why the Whale Logo?

Image

Image

Image

Image

Docker is inspired by real shipping containers.

Shipping containers:

  • Standard size
  • Work on ships, trucks, trains
  • Carry anything safely

Docker containers:

  • Standard software packaging
  • Run anywhere Docker exists
  • Carry apps safely

Same concept. Different world.


πŸ”‘ Other Important Theory Terms

πŸ“ Dockerfile

A text file that contains instructions to build an image.

Example instructions:

  • FROM
  • RUN
  • COPY
  • CMD
  • EXPOSE

🏬 Docker Hub

A registry (like GitHub for images).

You can:

  • Pull public images
  • Push your own images

πŸ’Ύ Volumes

Special storage outside containers.

Why?
Containers are temporary.
Volumes store:

  • Database data
  • Uploaded files
  • Logs

Even if container is deleted.


βš™ docker run vs docker compose

Command Purpose
docker run Start one container
docker compose Manage multiple containers

Example:
Web app + Database + Redis β†’ use Compose.


🧠 One-Sentence Mental Model

Docker turns your app and its entire environment into a portable image.
You run that image as an isolated container β€” identical everywhere.

If this makes sense, you’re ready for practice.


πŸš€ PART 2 – Hands-On Docker (Beginner Friendly)

Now let’s actually run Docker.


βœ… Step 1: Install Docker

Download Docker Desktop:

https://www.docker.com/products/docker-desktop/

Verify installation:

docker --version
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ Step 2: Run Your First Container

docker run hello-world
Enter fullscreen mode Exit fullscreen mode

If you see a success message β€” Docker is working.


🌐 Run a Real Web Server (Nginx)

docker run -d -p 8080:80 nginx
Enter fullscreen mode Exit fullscreen mode

What this means:

  • -d β†’ Run in background
  • -p 8080:80 β†’ Map port
  • nginx β†’ Image name

Open browser:

http://localhost:8080
Enter fullscreen mode Exit fullscreen mode

You’ll see the Nginx page πŸŽ‰


πŸ“‹ Basic Commands You Must Know

List running containers

docker ps
Enter fullscreen mode Exit fullscreen mode

List all containers

docker ps -a
Enter fullscreen mode Exit fullscreen mode

List images

docker images
Enter fullscreen mode Exit fullscreen mode

Stop container

docker stop <container_id>
Enter fullscreen mode Exit fullscreen mode

Remove container

docker rm <container_id>
Enter fullscreen mode Exit fullscreen mode

Remove image

docker rmi <image_name>
Enter fullscreen mode Exit fullscreen mode

πŸ—„ Example: Run PostgreSQL Database

docker run -d \
  --name my-postgres \
  -e POSTGRES_PASSWORD=mysecretpassword \
  -p 5432:5432 \
  -v pgdata:/var/lib/postgresql/data \
  postgres:16
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • -e β†’ Environment variable
  • -v β†’ Volume (persistent storage)
  • -p β†’ Port mapping

πŸ§‘β€πŸ’» Build Your Own Docker Image (Mini Project)

Create folder:

my-first-docker-app
Enter fullscreen mode Exit fullscreen mode

Inside it create:

app.py

print("Hello from my first Docker container πŸš€")
Enter fullscreen mode Exit fullscreen mode

Dockerfile

FROM python:3.12-slim

WORKDIR /app

COPY app.py .

CMD ["python", "app.py"]
Enter fullscreen mode Exit fullscreen mode

πŸ”¨ Build Image

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

β–Ά Run Container

docker run my-first-app
Enter fullscreen mode Exit fullscreen mode

If it prints your message:

Congratulations πŸŽ‰
You just built and ran your own Docker image.


🧩 Understanding Port Mapping

Format:

-p host_port:container_port
Enter fullscreen mode Exit fullscreen mode

Example:

-p 5000:3000
Enter fullscreen mode Exit fullscreen mode

Means:

  • Access via localhost:5000
  • App runs inside container on port 3000

🎯 Why Developers Love Docker

βœ… Same environment everywhere
βœ… No dependency conflicts
βœ… Fast setup
βœ… Easy deployment
βœ… Works with CI/CD
βœ… Cloud-ready

Happy Containerizing ,please like this post 🐳

Top comments (0)