Welcome to the comprehensive Docker learning repository! This collection contains practical examples and demonstrations of Docker concepts, from basic containerization to advanced orchestration techniques.
Folder | Description | Skills Covered |
---|---|---|
Docker_Simple_Image | Basic Flask app containerization | Dockerfile basics, image building, container running |
Docker_Compose | Multi-service application orchestration | Docker Compose, service definitions, networking |
Docker_MultiStageBuild | Optimized image building techniques | Multi-stage builds, image size optimization |
Docker_Networks | Container networking concepts | Network types, communication, isolation |
Docker_Volume | Data persistence and sharing | Volume management, data persistence |
π All examples include detailed
.md
documentation - feel free to explore, use, and execute!
Docker is a containerization platform that packages applications and their dependencies into lightweight, portable containers. Think of it as a shipping container for software - it ensures your application runs consistently anywhere Docker is installed.
- β Consistency: "It works on my machine" becomes "It works everywhere"
- β Portability: Run the same container on development, testing, and production
- β Efficiency: Share resources better than traditional VMs
- β Scalability: Easy horizontal scaling and microservices architecture
A container is a lightweight, standalone executable package that includes:
- ποΈ Application code
- π§ Runtime environment
- π System libraries
- βοΈ Dependencies
- π¨ Configuration files
Containers vs VMs: While VMs virtualize entire operating systems, containers share the host OS kernel, making them much more efficient.
graph TD
A[Docker CLI] -->|Commands| B[Docker Daemon]
B -->|Manages| C[containerd]
C -->|Runtime| D[runc]
D -->|Creates| E[Container]
B -->|Pulls/Stores| F[Docker Images]
F -->|Instance| E
B -->|Manages| G[Networks]
B -->|Manages| H[Volumes]
- π» User-facing interface for Docker commands
- π Communicates with Docker Daemon via REST API
- π Examples:
docker build
,docker run
,docker ps
- π§ Core engine that manages Docker objects
- π Handles image building, container lifecycle
- π Exposes REST API for Docker CLI communication
- π‘ Can communicate with other daemons for distributed deployments
- π High-level container runtime
- π Manages container lifecycle (start, stop, pause, delete)
- π¦ Handles image transfers and storage
- π§ Industry-standard container runtime
- β‘ Low-level container runtime
- π Actually creates and runs containers
- π Implements OCI (Open Container Initiative) specification
- π Handles container isolation and security
- πΈ Read-only templates for creating containers
- π§± Built in layers for efficiency and reusability
- πΎ Stored in registries (Docker Hub, private registries)
- π Versioned and shareable
graph LR
A[Python App<br/>app.py] -->|1. Create| B[Dockerfile]
B -->|2. Build| C[Docker Image]
C -->|3. Run| D[Docker Container]
subgraph "Build Process"
B1[FROM ubuntu:22.04]
B2[RUN install python]
B3[COPY app.py]
B4[CMD run app]
B1 --> B2 --> B3 --> B4
end
subgraph "Runtime"
D1[Isolated Process]
D2[Own Filesystem]
D3[Network Interface]
D4[Resource Limits]
end
-
π Write Application (
app.py
)# Your Python application code
-
ποΈ Create Dockerfile
FROM ubuntu:22.04 RUN apt-get update && apt-get install -y python3 COPY app.py /app/ CMD ["python3", "/app/app.py"]
-
π¨ Build Image
docker build -t my-app .
-
π Run Container
docker run -p 8080:8080 my-app
Aspect | π Docker Containers | π₯οΈ Virtual Machines |
---|---|---|
Resource Usage | Lightweight - shares host OS kernel | Heavy - each VM runs full OS |
Startup Time | Seconds β‘ | Minutes π |
Isolation | Process-level isolation | Hardware-level isolation |
Portability | High - runs anywhere Docker exists | Medium - depends on hypervisor |
Resource Overhead | Minimal | Significant |
"Like having separate apartments in a building - each has its own utilities, kitchen, and living space (full OS). Secure but resource-heavy."
"Like having separate rooms in a shared house - each room is private, but they share utilities (OS kernel). Efficient and lightweight."
"Containers are like running apps natively, VMs are like running apps inside another computer. Containers win on speed and efficiency."
sequenceDiagram
participant User
participant CLI as Docker CLI
participant Daemon as Docker Daemon
participant containerd
participant runc
participant Container
User->>CLI: docker run nginx
CLI->>Daemon: REST API call
Daemon->>Daemon: Check if image exists locally
alt Image not found
Daemon->>Registry: Pull nginx image
Registry->>Daemon: Image layers
end
Daemon->>containerd: Create container
containerd->>runc: Start container
runc->>Container: Create isolated process
Container->>User: Application running
Note over User,Container: Container is now running nginx web server
- Docker installed on your system
- Basic command line knowledge
-
Navigate to any folder:
cd Docker_Simple_Image
-
Follow the README.md in that folder
-
Build and run:
docker build -t example-app . docker run -p 8080:8080 example-app
- π’ Start here:
Docker_Simple_Image
- Learn basic containerization - π‘ Next:
Docker_MultiStageBuild
- Optimize your images - π Then:
Docker_Volume
- Handle data persistence - π΅ After:
Docker_Networks
- Understand container communication - π£ Finally:
Docker_Compose
- Orchestrate multi-service applications
Feel free to:
- π Report issues
- π‘ Suggest improvements
- π Add more examples
- π§ Submit pull requests
Happy Dockerizing! π³β¨