Skip to content

🐳 Docker – Full Beginner Tutorial (Concepts + Example Commands)

Goal: You should understand what happens, not just what to type.


1️⃣ Why Docker Exists (With Example)

Concept

Applications fail across machines because:

  • OS versions differ
  • Library versions differ
  • Runtime versions differ

Docker packages the environment with the app.

Example Command (just for idea)

docker run node:18

📌 Meaning:

  • You instantly get Node.js 18
  • No installation on your system
  • Same environment everywhere

2️⃣ What Docker Actually Runs

Concept

Docker runs:

  • A process
  • In an isolated environment
  • Using the host OS kernel

It does NOT run a full OS.

Example

docker run ubuntu

What actually happens:

  • Ubuntu filesystem is loaded
  • Ubuntu kernel is NOT loaded
  • Host Linux kernel is reused

3️⃣ Docker Architecture (Client → Engine)

Concept Flow

You → Docker CLI → Docker Engine → Container

You talk to Docker Docker Engine does the work

Example

docker ps

Meaning:

  • CLI asks Engine:

“Which containers are running?”


4️⃣ Docker Images (Blueprint)

Concept

An image is:

  • Read-only
  • Layered
  • Reusable

Image ≠ Running app Image = Template

Example

docker images

Shows:

  • All blueprints available locally

5️⃣ Docker Containers (Running Instance)

Concept

A container is:

  • A running image
  • Has its own filesystem & network
  • Is temporary by default

Example

docker run nginx

Meaning:

  • Image → Container
  • App starts running

6️⃣ Image Layers (Why Docker Is Efficient)

Concept

Images are built in layers:

Layer 1 → OS base
Layer 2 → Runtime
Layer 3 → Dependencies
Layer 4 → App code

Docker reuses unchanged layers.

Example

docker pull node:18

If another image uses Node 18:

  • Docker reuses existing layers
  • Saves time & space

7️⃣ Dockerfile (How Images Are Built)

Concept

A Dockerfile:

  • Is a recipe
  • Describes how to build an image

Example Dockerfile

FROM node:18
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "server.js"]

Example Build Command

docker build -t my-app .

Meaning:

  • Docker reads instructions
  • Builds image layer by layer

8️⃣ Build Time vs Run Time

Concept

Phase What Happens
Build Dependencies installed
Run App starts

Example

docker build -t my-app .
docker run my-app

You build once, run many times.


9️⃣ Container Isolation (Namespaces)

Concept

Each container has:

  • Its own process list
  • Its own network
  • Its own filesystem view

Example

docker exec -it container_id bash

Meaning:

  • You enter the container
  • It feels like a separate system
  • But kernel is shared

🔟 Networking (Ports Explained)

Concept

Containers have internal ports Host has external ports

Docker maps them.

Example

docker run -p 8080:80 nginx

Meaning:

Browser → Host:8080 → Container:80

1️⃣1️⃣ Storage (Why Containers Lose Data)

Concept

Containers are ephemeral:

  • Delete container → data lost

Solution: Volumes

Example

docker volume create mydata
docker run -v mydata:/data app

Meaning:

  • Data stored outside container
  • Safe even if container dies

1️⃣2️⃣ Environment Configuration

Concept

Same image, different environments:

  • Dev
  • Test
  • Prod

Config is injected at runtime.

Example

docker run -e DB_HOST=prod-db app

Meaning:

  • No code change
  • Only config changes

1️⃣3️⃣ Why Docker Starts Fast

Concept

Containers:

  • Don’t boot OS
  • Start like a process

Example

docker start container_id

Starts in milliseconds, not minutes.


1️⃣4️⃣ Docker for Multi-Service Apps

Concept

Modern apps = multiple services

Example:

  • Frontend
  • Backend
  • Database

Each runs in its own container.

Example Idea

docker run backend
docker run frontend
docker run database

Later → Docker Compose (automation)


1️⃣5️⃣ Docker in CI/CD

Concept

Docker enables:

  • Build once
  • Test once
  • Deploy everywhere

Example Flow

docker build
docker test
docker push
docker deploy

Same image moves across pipeline.


1️⃣6️⃣ Security (Simple View)

Concept

Docker provides:

  • Isolation
  • Resource limits

But:

  • Shared kernel
  • Needs best practices

Example

docker run --memory=512m app

Limits container RAM usage.


1️⃣7️⃣ Mental Model (MOST IMPORTANT)

Always think:

“Docker runs my app as an isolated process with its own filesystem and network, sharing the host kernel.”

If this clicks — Docker clicks.


✅ Final Summary

  • Image = Blueprint
  • Container = Running app
  • Dockerfile = Recipe
  • Engine = Worker
  • Registry = Storage
  • Kernel = Shared