Skip to content

Commit 69b0952

Browse files
committed
added new docs for docker...
1 parent eb70d92 commit 69b0952

File tree

10 files changed

+770
-98
lines changed

10 files changed

+770
-98
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Docker & Containers",
3+
"position": 5,
4+
"link": {
5+
"type": "generated-index",
6+
"description": "Stop worrying about environment issues. Learn how to package your code, libraries, and dependencies into a single, portable unit that runs anywhere. Docker is a powerful tool that simplifies application deployment and management. Whether you're a developer or a system administrator, mastering Docker will enhance your workflow and enable you to build, ship, and run applications with ease."
7+
}
8+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
sidebar_position: 2
3+
title: "Docker Architecture: Under the Hood"
4+
sidebar_label: "2. Docker Architecture"
5+
description: " Learn how Docker's Client-Server architecture works, the role of the Docker Daemon, and how images and containers interact. This foundational knowledge will help you troubleshoot and optimize your Docker workflows."
6+
---
7+
8+
Docker uses a **Client-Server** architecture. Most beginners think that when they type a command, the terminal "is" Docker. In reality, the terminal is just a remote control talking to a powerful engine running in the background.
9+
10+
## The Three Pillars of Docker
11+
12+
Here is how the components interact when you want to run a container:
13+
14+
```mermaid
15+
graph LR
16+
subgraph "Client (User Interface)"
17+
A[docker build]
18+
B[docker pull]
19+
C[docker run]
20+
end
21+
22+
subgraph "Docker Host (The Engine)"
23+
D[Docker Daemon]
24+
E[Images]
25+
F[Containers]
26+
D --> E
27+
D --> F
28+
end
29+
30+
subgraph "Registry (Cloud Storage)"
31+
G[Docker Hub]
32+
H[Private Registry]
33+
end
34+
35+
A --> D
36+
B --> G
37+
C --> D
38+
E --> F
39+
D -- Pulls --> G
40+
```
41+
42+
In this architecture:
43+
1. **Client:** The command-line tool you use to interact with Docker.
44+
2. **Docker Host:** The machine where the Docker Daemon runs and manages your containers.
45+
3. **Registry:** A storage and distribution system for Docker images (like Docker Hub).
46+
47+
## 1. The Docker Client (The Messenger)
48+
49+
The Client is the primary way users interact with Docker. When you type `docker run`, the client sends this command to the **Docker Daemon** using a REST API.
50+
51+
* **Analogy:** The remote control for your TV.
52+
53+
## 2. The Docker Host (The Engine Room)
54+
55+
This is where the "real" Docker lives. It consists of:
56+
57+
* **Docker Daemon (`dockerd`):** A background service that manages Docker objects like images, containers, networks, and volumes.
58+
* **Objects:**
59+
* **Images:** Read-only templates used to create containers.
60+
* **Containers:** The running instances of images.
61+
62+
## 3. Docker Registry (The Library)
63+
64+
A Registry is a stateless, highly scalable server side application that stores and lets you distribute Docker images.
65+
66+
* **Docker Hub:** The default public registry. It’s the "GitHub of Docker Images."
67+
* **The Flow:**
68+
1. You **Build** an image on your Host.
69+
2. You **Push** it to the Registry.
70+
3. Your teammate **Pulls** it from the Registry to their Host.
71+
72+
## The Logic of a Command
73+
74+
When you run `docker run hello-world`, the architecture follows this math:
75+
76+
$$Command \rightarrow Client \rightarrow API \rightarrow Daemon \rightarrow Registry \text{ (if not local)} \rightarrow Container$$
77+
78+
1. **Client** tells the **Daemon** to run "hello-world".
79+
2. **Daemon** checks if the "hello-world" **Image** is in the local **Host** library.
80+
3. If **NOT**, the Daemon reaches out to **Docker Hub** (Registry) to download it.
81+
4. **Daemon** creates a new **Container** from that image and executes it.
82+
83+
## Why this matters for DevOps
84+
85+
At **CodeHarborHub**, we often separate these parts:
86+
87+
* Your **Client** might be on your Windows laptop.
88+
* Your **Host** might be a powerful Linux server in the cloud (AWS/Azure).
89+
* Your **Registry** might be a private storage for your company's secret code.
90+
91+
By separating the "Control" (Client) from the "Execution" (Host), Docker allows us to manage thousands of servers from one single terminal.
92+
93+
## Summary Checklist
94+
95+
* [x] I understand that the **Client** and **Daemon** can be on different machines.
96+
* [x] I know that the **Daemon** is the one that actually manages containers.
97+
* [x] I can explain that **Docker Hub** is a type of Registry.
98+
* [x] I understand the flow of a `docker run` command.
99+
100+
:::info Note
101+
On Windows and Mac, "Docker Desktop" runs a tiny, invisible Linux Virtual Machine to act as the **Docker Host**, because the Docker Daemon needs a Linux Kernel to work!
102+
:::
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
---
2+
sidebar_position: 7
3+
title: "Docker Compose: The Fleet Commander"
4+
sidebar_label: "7. Docker Compose"
5+
description: "Learn how to orchestrate multiple containers (Frontend, Backend, DB) using a single YAML file. Understand the key keywords like services, build, ports, and depends_on. Master the essential docker-compose commands to manage your entire stack with ease."
6+
---
7+
8+
Until now, if you wanted to run a Full-stack app, you had to:
9+
1. Create a network.
10+
2. Start the Database container.
11+
3. Start the Backend container (linking it to the DB).
12+
4. Start the Frontend container (linking it to the Backend).
13+
14+
That is a lot of typing! **Docker Compose** allows you to write all these instructions in a single `docker-compose.yml` file. When you run `docker-compose up`, Docker reads the file and starts everything in the correct order. It's like being a **Fleet Commander** instead of a solo driver.
15+
16+
## 1. The "Orchestra" Analogy
17+
18+
Think of your containers as **Musicians**:
19+
* **The Dockerfile:** Is the sheet music for *one* instrument (e.g., just the Violin).
20+
* **Docker Compose:** Is the **Conductor**. The conductor doesn't play an instrument; they tell every musician when to start, how loud to play, and how to stay in sync.
21+
22+
## 2. The YAML Blueprint
23+
24+
Docker Compose uses **YAML** (Yet Another Markup Language). It is easy to read because it uses indentation instead of curly braces.
25+
26+
Here is a standard `docker-compose.yml` for a **CodeHarborHub** project:
27+
28+
```yaml
29+
version: '3.8'
30+
31+
services:
32+
frontend:
33+
build: ./frontend
34+
ports:
35+
- "3000:3000"
36+
depends_on:
37+
- backend
38+
39+
backend:
40+
build: ./backend
41+
ports:
42+
- "5000:5000"
43+
environment:
44+
- DB_URL=mongodb://database:27017/hub_db
45+
depends_on:
46+
- database
47+
48+
database:
49+
image: mongo:latest
50+
volumes:
51+
- hub_data:/data/db
52+
53+
volumes:
54+
hub_data:
55+
```
56+
57+
## 3. The 3 Steps of Compose
58+
59+
To get your entire system running, you only need three steps:
60+
61+
1. **Define** each service's environment with its own `Dockerfile`.
62+
2. **Define** how they connect in the `docker-compose.yml`.
63+
3. **Run** `docker-compose up` to start the whole world.
64+
65+
## 4. Key Keywords to Remember
66+
67+
* **services:** These are your containers (e.g., `web`, `api`, `db`).
68+
* **build:** Tells Docker to look for a `Dockerfile` in a specific folder.
69+
* **image:** Tells Docker to download a pre-built image instead of building one.
70+
* **ports:** Maps the Host port to the Container port (just like `-p`).
71+
* **depends_on:** Tells Docker the order of operations (e.g., "Don't start the Backend until the Database is ready").
72+
* **environment:** Passes variables (like API keys) into the container.
73+
74+
## The Logic of Orchestration
75+
76+
When you run `docker-compose up`, Docker performs the following "Math":
77+
78+
```mermaid
79+
graph TD
80+
A[Read docker-compose.yml] --> B[Create shared Network]
81+
B --> C[Create shared Volumes]
82+
C --> D[Pull/Build Images]
83+
D --> E[Start Containers in Order]
84+
E --> F{Health Check}
85+
```
86+
87+
$$Total\_Stack = (Net + Vol) + \sum(Service_{1...n})$$
88+
89+
Where:
90+
91+
* **Net:** The shared network for all services.
92+
* **Vol:** The shared volumes for data persistence.
93+
* **Service:** Each individual container with its own configuration.
94+
95+
## Essential Compose Commands
96+
97+
| Command | Action |
98+
| :--- | :--- |
99+
| `docker-compose up` | Build, create, and start all containers. |
100+
| `docker-compose up -d` | Run everything in the background (Detached). |
101+
| `docker-compose ps` | See the status of your entire stack. |
102+
| `docker-compose logs -f` | Watch the output from all containers at once. |
103+
| `docker-compose stop` | Stop the services (but keep the containers). |
104+
| `docker-compose down` | **The Cleanup:** Stop and REMOVE all containers and networks. |
105+
106+
## Summary Checklist
107+
* [x] I understand that Compose is for **multi-container** apps.
108+
* [x] I know that `docker-compose.yml` uses YAML indentation.
109+
* [x] I can explain what `depends_on` does for startup order.
110+
* [x] I understand that `docker-compose down` wipes the environment clean.
111+
112+
:::success 🎉 Docker Module Complete!
113+
Congratulations! You have moved from a simple "Hello World" to orchestrating a complex, multi-service architecture. You are now officially a **Container Pro**.
114+
:::
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
sidebar_position: 6
3+
title: "Docker Networking: How Containers Talk to Each Other"
4+
sidebar_label: "6. Docker Networking"
5+
description: "Learn about Bridge networks, Host networking, and how to expose your apps to the world. Understand port mapping and service discovery in Docker."
6+
---
7+
8+
In a modern application, a **React Frontend** needs to talk to a **Node.js API**, which needs to talk to a **MongoDB Database**. If these were three separate physical servers, you would need cables. In Docker, we use **Virtual Networks**.
9+
10+
## 1. The "Gated Community" Analogy
11+
12+
Think of Docker Networking like a **Gated Community**:
13+
* **The Containers:** These are the houses.
14+
* **The Bridge Network:** This is the private internal road inside the community. Houses can talk to each other easily using their "Names" (DNS).
15+
* **Port Mapping:** This is the "Main Gate." If someone from the outside world (the Internet) wants to visit, they must come through a specific gate number.
16+
17+
## 2. The Three Main Network Drivers
18+
19+
Docker provides different "Drivers" depending on how much isolation you need:
20+
21+
### A. Bridge Network (The Default)
22+
The most common choice for **CodeHarborHub** projects. It creates a private space on your computer.
23+
* **Key Feature:** Containers can talk to each other using their **Container Name**.
24+
* **Usage:** `docker run --network my-bridge-net ...`
25+
26+
### B. Host Network
27+
The container shares the **exact same IP and Ports** as your actual laptop/server. There is no isolation.
28+
* **Key Feature:** Best for high-performance apps, but dangerous because ports can clash.
29+
30+
### C. None
31+
The container has no network access at all. Total "Air-gap" security.
32+
33+
## 3. Port Mapping: Opening the Gates
34+
35+
By default, an app running inside a container on port `3000` is invisible to your browser. You must "Map" a port from your **Host** to the **Container**.
36+
37+
**The Formula:** `-p [Host_Port]:[Container_Port]`
38+
39+
```bash
40+
docker run -p 8080:3000 my-web-app
41+
```
42+
43+
* **Host Port (8080):** What you type in your browser (`localhost:8080`).
44+
* **Container Port (3000):** Where the app is actually listening inside the "box."
45+
46+
## 4. Automatic Service Discovery
47+
48+
This is the "Magic" of Docker. If you put two containers on the same user-defined network, you don't need to know their IP addresses\!
49+
50+
```mermaid
51+
graph LR
52+
subgraph "Custom Bridge Network"
53+
A[Frontend Container] -- "http://api-server:5000" --> B[Backend Container]
54+
B -- "mongodb://db-server:27017" --> C[Database Container]
55+
end
56+
```
57+
58+
Docker acts as a mini **DNS Server**. It knows that `api-server` belongs to the Backend container's IP address. This means you can write your code using friendly names instead of hard-coding IPs, which can change every time you restart the containers.
59+
60+
## Essential Networking Commands
61+
62+
| Command | Action |
63+
| :--- | :--- |
64+
| `docker network ls` | See all virtual networks on your machine. |
65+
| `docker network create hub-net` | Create a new private road for your apps. |
66+
| `docker network inspect hub-net` | See which containers are currently connected. |
67+
| `docker network connect hub-net app1` | Add an existing container to a network. |
68+
69+
## The Math of Conflict
70+
71+
If you try to run two containers mapping to the same Host Port, Docker will throw an error:
72+
73+
$$Error = \text{Host\_Port\_8080} \in \text{Already\_In\_Use}$$
74+
75+
**Solution:** Map them to different host ports:
76+
77+
* Container A: `-p 8080:80`
78+
* Container B: `-p 8081:80`
79+
80+
## Summary Checklist
81+
82+
* [x] I understand that **Bridge** is the default network for isolated apps.
83+
* [x] I can explain **Port Mapping** (`-p host:container`).
84+
* [x] I know that containers on the same network can talk using **Names** instead of IPs.
85+
* [x] I understand that `localhost` inside a container refers to the container itself, not my laptop.
86+
87+
:::info Note
88+
Never use the default "bridge" network for production. Always create your own named network (`docker network create ...`). Only **named networks** allow containers to look each other up by name!
89+
:::

0 commit comments

Comments
 (0)