Day 01: Containers vs VMs | Docker Architecture, Installation, Networking, and Commands
Understanding Hardware and Software Components
Before diving into Docker and containers, let’s understand the key hardware and software components that make up a computing environment.
Hardware Components:
CPU (Central Processing Unit): The brain of the computer responsible for executing instructions.
RAM (Random Access Memory): Temporary storage for active processes and applications.
Hard Drive (HD): Permanent storage for operating systems, applications, and data.
Graphic Cards: Dedicated hardware for rendering images and video.
Software Components:
Operating System (OS): The core software managing hardware resources and applications.
Applications: Software programs that users interact with, such as browsers, editors, or recorders.
The Kernel
The kernel is the core part of an operating system, acting as a bridge between software and hardware. It converts software requests into hardware instructions, allowing applications to run efficiently.
Container Runtimes
Container runtimes are essential for running containers. Common container runtimes include:
ContainerD (Used in production environments)
Docker (Preferred for local development and testing)
CRI-O (Used in Kubernetes clusters)
Note: Developers often use Docker for local testing(KIND CLUSTER), whereas production environments favor ContainerD for better performance and security.
Containers vs Virtual Machines (VMs)
Virtual Machines (VMs)
VMs are full-fledged operating systems running on a hypervisor.
Each VM has its own dedicated OS, libraries, and dependencies.
VMs are heavy and take longer to boot due to the full OS load.
Highly isolated environments ensuring strong security.
Containers
Containers share the same OS kernel but provide isolated environments for applications.
They are lightweight and start quickly since they don’t require a full OS.
Less isolated compared to VMs but provide efficient resource utilization.
Docker Architecture
Docker is a platform that allows developers to package applications and their dependencies into lightweight containers.
Key Components:
Docker Client
Acts as the command-line interface for Docker.
Sends commands to the Docker Daemon.
Example commands:
docker build
,docker run
,docker pull
Docker Daemon
Runs on the host system and manages containers.
Handles container lifecycle, images, networks, and storage.
Docker Registry
A storage system for Docker images.
Docker Hub is a public registry where users can find and share container images.
Organizations use private registries to manage internal container images securely.
Installing Docker & Networking
To install Docker on Linux:
curl https://get.docker.com/ | bash
Docker Network Types
Bridge Network: Default network mode for containers on a single host, allowing communication between containers.
Host Network: Removes isolation between the container and host network, providing direct access to the host’s networking.
None Network: Disables networking for the container, providing a fully isolated environment.
Basic Docker Commands
Checking Docker Installation
docker version
Listing Namespaces
lsns # List all namespaces
lsns -t pid # List only PID namespaces
Running a Container
docker run --name app1 nginx:latest
Running a Container in the Background
docker run -d --name app1 nginx:latest
Creating Multiple Containers
for i in {1..10}; do docker run -d nginx:latest; done
Listing Running Containers
docker ps
Stopping All Containers
docker stop $(docker ps -aq)
Deploying and Removing a Container
docker run --rm -d --name app1 nginx:latest
Inspecting a Container
docker inspect app1
Port Forwarding
docker run --rm -d --name app1 -p 8000:80 nginx:latest
Viewing Container Logs
docker logs app1 -f
Install jq tool to see logs in more user friendly way
Conclusion
Docker simplifies application deployment by using lightweight containers that share the same OS kernel while maintaining process isolation. Understanding Docker's architecture, networking, and commands is crucial for managing containerized applications efficiently. Stay tuned for the next blog in this series, where we dive deeper into Docker images and container orchestration!