1. Introduction

ðŸ”đ Introduction to Docker

If you’ve ever faced the dreaded “It works on my machine but not on yours” problem — Docker is the hero you need.

Docker allows developers to package applications into isolated environments called containers, ensuring they run the same everywhere.

✅ Think of it like this:
You built a school project website that runs fine on your laptop.
But when you copy it to your friend’s system, it crashes because they have a different PHP version.

With Docker, you can package:

into a single container.
Now it works everywhere 🚀.


⚙ïļ Docker Architecture

Docker has two main parts:

ðŸ–Ĩïļ 1. Docker Client

The tool we use to interact with Docker.

Runs commands like:

Can also communicate with a remote Docker Daemon over a network.


⚡ 2. Docker Daemon

The engine of Docker running in the background.

Responsible for:


Client ↔ Daemon communicate via:

👉 Analogy:
You (client) say “Make tea!” ☕ and the kitchen (daemon) makes it.


ðŸ§Đ Docker Components

ðŸ“Ķ 1. Docker Images

If one layer changes, only that part rebuilds.

👉 Example:

docker pull ubuntu
docker pull ubuntu

🏃 2. Docker Containers

By default, containers are ephemeral (data is lost when removed) unless a volume is attached.

📌 Flow:

  1. Pull image
  2. Create container
  3. Add read-write layer
  4. Connect to virtual network
  5. Get unique container IP
  6. Interact via terminal
docker container create --name shan ubuntu /bin/bash
docker container create --name shan ubuntu /bin/bash

ðŸ”Ĩ 3. Docker Engine

The core runtime that builds and runs containers locally.


☁ïļ 4. Docker Hub

A cloud-based repository to store and share Docker images.


📝 5. Dockerfile

A script with step-by-step instructions to build an image.
Executed top to bottom by the Docker Daemon.

📌 Workflow:
Dockerfile → docker build → Docker Image → docker run → Container

✅ Example:

FROM ubuntu
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]
FROM ubuntu
RUN apt-get update && apt-get install -y nginx
CMD ["nginx", "-g", "daemon off;"]

ðŸ“Ķ Docker Registry

A service that stores Docker images.
Docker Hub is the most popular public registry.


🔧 Common Docker Commands

ðŸ”đ Image Commands

ðŸ”đ Container Commands

👉 Example: Run Nginx on port 80

docker run -d -p 80:80 nginx
docker run -d -p 80:80 nginx

ðŸĨŠ Docker vs Virtual Machine

Feature Docker (Container) Virtual Machine (VM)
Startup Time Seconds ⚡ Minutes 🕒
Resource Usage Lightweight ðŸŠķ Heavy ðŸ’ŧ
OS Requirement Shares Host OS Needs Full OS
Performance Faster 🚀 Slower ðŸĒ
Isolation Process-level Hardware-level

👉 Example: