Day 6:Virtual Machine & Containerization(Docker Beginning)


✅ What is a VM (Virtual Machine)?
A Virtual Machine is a software-based simulation of a physical computer. It runs on a hypervisor like VMware, VirtualBox, or KVM, which sits on top of the host OS or hardware.
Each VM has its own OS, libraries, and applications.
It uses virtual hardware (CPU, memory, storage, etc.)
VMs are isolated from one another.
🖼 Example:
Running Ubuntu and Windows simultaneously on a macOS laptop via VirtualBox.
✅ What is Containerization?
Containerization is a lightweight form of virtualization using containers, which share the host system’s kernel but have isolated environments.
Containers are created using tools like Docker or Podman.
Containers share the host OS but have their own filesystem, libraries, and dependencies.
They are much more lightweight and faster to start than VMs.
🖼 Example:
Running multiple Python apps in isolated Docker containers on the same host OS.
✅ Use Cases
Use Case | VM | Container |
Run different OSes | ✅ Yes (e.g., Linux on Windows) | ❌ No (shares host OS kernel) |
Legacy application | ✅ Yes | ⚠️ Sometimes (depending on dependencies) |
Microservices deployment | ❌ Heavy | ✅ Ideal for microservices |
Development & Testing | ✅ Commonly used | ✅ Faster and more efficient |
✅ Advantages of VMs over Containers
Advantage | Why it matters |
Strong Isolation | VMs don't share OS kernel, offering better security |
Different OS Support | VMs can run any OS (Linux, Windows, etc.) |
Better for Monolithic Apps | Useful for large, legacy applications needing full OS |
Mature Ecosystem | VM tools and platforms have existed longer (e.g., VMware) |
✅Architecture Of Docker
Here’s a clear and concise explanation of the Docker architecture, including its components and how they work together.
🐳 Docker Architecture Overview
Docker uses a client-server architecture consisting of:
Docker Client
Docker Daemon (Server)
Docker Objects (Images, Containers, Volumes, etc.)
Docker Registry (e.g., Docker Hub)
📌 1. Docker Client (docker
command)
It's what you interact with via terminal or scripts.
Sends commands like
docker build
,docker run
,docker pull
to the Docker Daemon.Communicates via REST API over UNIX socket or network.
🧠 Think of it as the "front-end" of Docker.
📌 2. Docker Daemon (dockerd
)
It's the main engine of Docker.
Listens for API requests from the Docker client.
Manages:
Containers
Images
Volumes
Networks
Runs as a background service on your system.
🧠 Think of it as the "brain" or "backend" of Docker.
📌 3. Docker Objects
🖼 a. Images
Blueprint or snapshot for containers.
Built from Dockerfile.
Immutable and layered.
📦 b. Containers
Running instances of images.
Lightweight and isolated.
Share the host OS kernel.
📂 c. Volumes
Persistent storage for containers.
Useful when container is deleted and data must persist.
🌐 d. Networks
- Used for communication between containers or external world.
📌 4. Docker Registry
Storage and distribution system for Docker images.
Default: Docker Hub
You can also use private registries (like AWS ECR, GitHub Container Registry, Harbor).
Common commands:
docker pull nginx
→ Pulls image from registrydocker push my-image
→ Pushes image to registry
🔁 Flow Diagram (Textual)
scssCopyEditUser
↓
Docker CLI (Client)
↓ (REST API)
Docker Daemon (dockerd)
├── Image Management
├── Container Management
├── Volume Management
└── Network Management
↓
Docker Registry (e.g., Docker Hub)
🧩 Example Flow
You run:
bashCopyEditdocker run nginx
What happens:
Docker Client sends request to Daemon
Daemon checks for
nginx
imageIf not present, it pulls from Docker Hub
Daemon creates and runs the container from the image
Container is isolated but shares host kernel
.
🚦 Docker Container Lifecycle
1️⃣ Created
The container is created but not running yet.
It’s based on an image and has a container ID assigned.
🛠️ Command:
bashCopyEditdocker create nginx
⏳ State:
Container exists on disk.
Not consuming CPU or memory.
2️⃣ Running
The container is actively executing the process inside.
It’s isolated but shares the host OS kernel.
🛠️ Command:
bashCopyEditdocker run nginx
(Equivalent to docker create + docker start
)
🟢 Status:
bashCopyEditdocker ps
3️⃣ Paused (optional)
Process is temporarily frozen (e.g., for maintenance).
Container remains in memory.
🛠️ Command:
bashCopyEditdocker pause <container_id>
docker unpause <container_id>
4️⃣ Stopped (Exited)
Container process has stopped (gracefully or forcibly).
Container still exists, so you can inspect logs or restart it.
🛠️ Commands:
bashCopyEditdocker stop <container_id> # Graceful
docker kill <container_id> # Force stop
📦 View stopped containers:
bashCopyEditdocker ps -a
5️⃣ Restarted (optional)
- Container is restarted after being stopped.
🛠️ Command:
bashCopyEditdocker restart <container_id>
You can also use --restart
policy like:
bashCopyEditdocker run --restart=always nginx
6️⃣ Removed
Container is completely deleted.
No logs, metadata, or filesystem remain.
🛠️ Commands:
bashCopyEditdocker rm <container_id>
docker container prune # Removes all stopped containers
If container is still running:
bashCopyEditdocker rm -f <container_id>
🔁 Lifecycle Summary Table
State | Description | Command |
Created | Container created but not started | docker create |
Running | Active container running a process | docker run / docker start |
Paused | Execution frozen | docker pause |
Stopped | Process exited | docker stop / docker kill |
Restarted | Re-run stopped container | docker restart |
Removed | Deleted from system | docker rm |
Subscribe to my newsletter
Read articles from Aditya Tiwary directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
