# Basic Concepts (EN & CH)
## [EN]
## ✅ 1. **Hardware**
### 🔹 What it is:
Physical computing resources — the **foundation layer** for everything. Includes:
* CPU (processor)
* RAM (memory)
* Storage (SSD/HDD)
* Network cards (NIC)
* GPU (optional)
### 🔹 Real-life Example:
* A **MacBook Pro** running Intel i7, 16GB RAM, and 512GB SSD.
* A **cloud server** from AWS EC2 or Google Cloud Compute Engine.
### 🔹 Usage:
* Hosts the **operating system**.
* Determines the limits of performance (CPU cores, available memory, etc.).
---
## ✅ 2. **Kernel**
### 🔹 What it is:
The **core part** of an operating system. It manages:
* Communication between hardware and software
* Resource allocation
* Process scheduling
* Memory and device control
> Think of the kernel as the "translator" between software apps and hardware.
### 🔹 Real-life Examples:
* **Linux kernel**: Used in Ubuntu, Red Hat, Android
* **Windows NT kernel**: Used in all modern Windows versions
### 🔹 Usage:
* If an app requests access to memory or disk, the kernel decides how and when.
* Docker **shares the host kernel** across all containers — that’s what makes it lightweight.
---
## ✅ 3. **Operating System (OS)**
### 🔹 What it is:
A **complete environment** that includes the kernel plus user-level tools, libraries, services, and a UI or CLI shell.
### 🔹 Real-life Examples:
* **Ubuntu**, **Debian**, **Fedora** (Linux-based)
* **Windows 11**
* **macOS**
* **Android**
### 🔹 Usage:
* You boot into your OS when you turn on your laptop.
* Developers choose OS based on toolchain compatibility (e.g., Linux for servers, Windows for .NET apps).
---
## ✅ 4. **Application**
### 🔹 What it is:
Software built by developers to run **on top of the operating system**. Can be:
* GUI-based
* CLI-based
* Server-side or client-side
### 🔹 Real-life Examples:
* **Google Chrome** (Web browser)
* **PostgreSQL** (Database)
* **Node.js API Server**
* **Nginx** (Web server)
* **Slack**, **VSCode**, **Zoom**
### 🔹 Usage:
* The programs users interact with or that power backend systems.
* In Docker, applications are packaged **with all their dependencies**.
---
## ✅ 5. **Virtual Machine (VM)**
### 🔹 What it is:
A **full software emulation of a computer**, including virtual CPU, memory, disk, and OS. Runs on a **hypervisor** (like VirtualBox or VMware).
Each VM includes:
* Its own OS
* Its own kernel
* Isolated from the host machine
### 🔹 Real-life Examples:
* Run **Ubuntu on Windows** using VirtualBox
* Deploy a **Windows Server 2019 VM** in Azure
* A developer uses a VM to test software in an isolated environment
### 🔹 Usage:
* Heavy-duty isolation
* Suitable for legacy software that depends on a full OS
* Common in enterprise environments
---
## ✅ 6. **Docker**
### 🔹 What it is:
A **containerization platform** that allows you to run applications in **isolated, lightweight environments** called containers.
Docker **does not emulate hardware** like a VM. Instead:
* It shares the host’s OS kernel
* Packages everything the app needs (code, runtime, system tools)
### 🔹 Real-life Examples:
* Run a **Node.js app** in a Docker container with all its dependencies
* Use **Docker Compose** to run a multi-service app (API + database + Redis)
* Deploy containers using **Kubernetes** or **AWS ECS**
### 🔹 Usage:
* Microservice architecture
* CI/CD pipelines
* Dev/prod consistency
* Easy rollback and replication
---
## 🔧 Architecture Diagram: Conceptual Overview
```
[Hardware: CPU, RAM, Disk]
↓
[Kernel: Linux/Windows NT]
↓
[Operating System: Ubuntu, Windows]
↓
┌──────────────┬──────────────┬───────────────┐
│ VirtualBox VM│ Docker Engine│ Native App │
│ (Ubuntu VM) │ (Containers) │ (Chrome, etc.)│
└──────────────┴──────────────┴───────────────┘
↓ ↓
[VM: OS + Kernel] [App + Libs + Files]
[Containerized App]
```
---
## ✅ Final Summary
| Layer | Scope | Isolation | Startup Time | Resource Usage | Example |
| ---------------- | ---------------- | --------- | ------------ | -------------- | ------------------------ |
| Hardware | Physical machine | N/A | N/A | N/A | MacBook, AWS EC2 |
| Kernel | Core of OS | Shared | Always on | Medium | Linux kernel, Windows NT |
| Operating System | System software | Full | Minutes | High | Ubuntu, Windows, macOS |
| Application | User software | Process | Seconds | Depends | Nginx, VSCode, Node.js |
| Virtual Machine | Emulated OS | Full | Minutes | High | VirtualBox, VMware |
| Docker | App container | Process | Seconds | Lightweight | Docker, Compose, K8s |
---
[CH]
---
## ✅ 1. **硬體(Hardware)**
### 🔹 什麼是硬體:
硬體是實體的電腦資源,是所有運算的**基礎層級**,包含:
* CPU(中央處理器)
* RAM(記憶體)
* 儲存裝置(SSD/HDD)
* 網路卡(NIC)
* GPU(圖形處理器,可選)
### 🔹 實際範例:
* 一台搭載 Intel i7、16GB RAM、512GB SSD 的 **MacBook Pro**
* 一台部署在 AWS EC2 或 Google Cloud 的雲端主機
### 🔹 使用場景:
* 作業系統會安裝在硬體上
* 決定可支援的效能上限(例如處理器核心數、記憶體大小)
---
## ✅ 2. **核心(Kernel)**
### 🔹 什麼是核心:
核心是作業系統的**核心組件**,負責:
* 軟體與硬體間的溝通
* 資源分配
* 行程排程
* 記憶體與裝置控制
> 可將核心視為軟體與硬體之間的「翻譯官」。
### 🔹 實際範例:
* **Linux 核心**:應用於 Ubuntu、Red Hat、Android
* **Windows NT 核心**:用於現代的所有 Windows 作業系統
### 🔹 使用場景:
* 當應用程式需要使用記憶體或硬碟時,由核心來控管
* Docker 容器會**共用主機的核心**,因此相較虛擬機更輕量
---
## ✅ 3. **作業系統(Operating System, OS)**
### 🔹 什麼是作業系統:
作業系統是一個**完整的運行環境**,包含核心、系統工具、程式庫、服務及使用者介面(UI/CLI)。
### 🔹 實際範例:
* Linux 系列:**Ubuntu**, **Debian**, **Fedora**
* 商用系統:**Windows 11**, **macOS**
* 行動裝置:**Android**
### 🔹 使用場景:
* 電腦開機後會載入作業系統
* 開發者根據專案需求選擇 OS(例如部署伺服器多用 Linux)
---
## ✅ 4. **應用程式(Application)**
### 🔹 什麼是應用程式:
開發人員撰寫的軟體,用於執行特定功能。可分為:
* 圖形介面(GUI)
* 命令列介面(CLI)
* 前端/後端應用程式
### 🔹 實際範例:
* **Google Chrome**(網頁瀏覽器)
* **PostgreSQL**(資料庫)
* **Node.js 應用伺服器**
* **Nginx**(Web Server)
* **Slack**, **VSCode**, **Zoom**
### 🔹 使用場景:
* 使用者或後端系統執行的實際程式
* 在 Docker 中,應用程式會被**與所有依賴一起打包進容器**
---
## ✅ 5. **虛擬機(Virtual Machine, VM)**
### 🔹 什麼是虛擬機:
完整模擬一台電腦環境,包括虛擬 CPU、記憶體、磁碟與作業系統,透過 **Hypervisor(虛擬機管理器)** 運行。
每個虛擬機都包含:
* 自己的作業系統
* 自己的核心
* 與主機完全隔離
### 🔹 實際範例:
* 在 Windows 上透過 VirtualBox 運行 **Ubuntu**
* 在 Azure 上部署 **Windows Server 2019 VM**
* 開發人員用虛擬機測試高風險軟體,避免影響主系統
### 🔹 使用場景:
* 需要完全隔離的測試環境
* 舊版應用程式或舊作業系統相容性需求
* 企業內部部署多個獨立系統
---
## ✅ 6. **Docker**
### 🔹 什麼是 Docker:
Docker 是一種**容器化平台**,可以讓應用程式在**輕量、隔離的環境中運行**,稱為「容器」。
Docker 與虛擬機不同:
* **不模擬硬體**
* 容器會**共用主機的核心**
* 每個容器都包含應用程式、相依檔案、程式庫等
### 🔹 實際範例:
* 使用 Docker 執行一個 **Node.js 應用程式**
* 使用 Docker Compose 同時啟動 API + 資料庫 + Redis
* 在 AWS、Kubernetes 上部署多個容器進行水平擴展
### 🔹 使用場景:
* 微服務架構
* CI/CD 自動化部署
* 開發與生產環境一致性
* 快速版本回滾、複製與測試
---
## 🔧 架構總覽圖(簡化示意)
```
[硬體]
↓
[核心]
↓
[作業系統]
↓
┌─────────────┬──────────────┬─────────────┐
│ 虛擬機器 │ Docker 容器引擎 │ 原生應用程式 │
│(完整作業系統)│(容器) │(安裝在 OS) │
└─────────────┴──────────────┴─────────────┘
```
---
# Summary Tables
## [EN]
## 🧩 **1. Docker vs Virtual Machine (VM)**
| Feature | **Docker (Container)** | **Virtual Machine (VM)** |
| ------------------------ | ----------------------------------------------- | ---------------------------------------------- |
| **Virtualization Layer** | OS-level (shares host kernel) | Hardware-level (emulates full hardware stack) |
| **Resource Usage** | Lightweight (shares OS, minimal overhead) | Heavy (requires full guest OS per VM) |
| **Startup Time** | Very fast (seconds) | Slower (minutes) |
| **Isolation Level** | Process-level (namespaces, cgroups) | Full system isolation |
| **Performance** | Near-native | Slower due to hardware emulation |
| **Use Case** | Microservices, dev/test, lightweight deployment | Full OS testing, legacy apps, strong isolation |
| **Size** | Small (MBs) | Large (GBs) |
| **Example Tools** | Docker, Podman, containerd | VirtualBox, VMware, Hyper-V |
---
## 🧱 **2. Hardware → Kernel → OS → Application → VM → Docker**
| Layer | **Description** | **Example** |
| -------------------- | ------------------------------------------------------------------- | ---------------------------------- |
| **Hardware** | Physical machine (CPU, RAM, disk, etc.) | Intel CPU, SSD, RAM, NIC |
| **Kernel** | Core of the OS, interfaces between hardware and software | Linux kernel, Windows NT kernel |
| **Operating System** | Full system with tools, services, libraries, and shell | Ubuntu, CentOS, Windows |
| **Application** | End-user programs or services running on the OS | Nginx, Node.js, VSCode |
| **Virtual Machine** | Emulated OS running on hypervisor (needs full OS + kernel) | Ubuntu VM on VirtualBox |
| **Docker (Engine)** | Container runtime that uses host OS kernel to run apps in isolation | Docker running a Node.js container |
---
## 🐳 **3. Docker Components Comparison**
| Component | **Description** |
| ------------------------- | -------------------------------------------------------------------------------------- |
| **Docker Image** | Read-only **blueprint** for creating containers. Contains app, dependencies, OS files. |
| **Docker Container** | **Running instance** of an image. Lightweight, isolated, shares host kernel. |
| **Container Environment** | The **runtime environment** inside a container (file system, libraries, app). |
---
## ⚙️ **Optional Docker Tooling (Bonus)**
| Tool/Component | Description |
| ------------------ | ----------------------------------------------------------------------- |
| **Docker Engine** | Core runtime that builds, runs, and manages containers |
| **Docker Compose** | Tool to define and run multi-container setups via `docker-compose.yml` |
| **Docker Toolbox** | Legacy bundle (before Docker Desktop) for Windows/macOS development |
| **Docker Machine** | Creates and manages Docker hosts on VMs/clouds (now deprecated) |
| **Kitematic** | GUI for managing Docker containers (discontinued, once part of Toolbox) |
---
## [CH]
以下是「**Docker 容器 vs 虛擬機器(VM)**」的比較表格(繁體中文版本):
---
## 🧩 **1. Docker 與虛擬機(VM)比較**
| 功能項目 | **Docker(容器)** | **虛擬機(VM)** |
| --------- | ------------------------------- | ------------------------- |
| **虛擬化層級** | 作業系統層級(共用主機核心) | 硬體層級(模擬完整硬體堆疊) |
| **資源使用量** | 輕量(共用作業系統,開銷小) | 較重(每個 VM 需要完整作業系統) |
| **啟動速度** | 非常快(幾秒鐘即可啟動) | 較慢(需要數分鐘來啟動整個作業系統) |
| **隔離等級** | 程式層級隔離(使用 namespaces 和 cgroups) | 完整系統隔離(每台 VM 都有獨立的核心與 OS) |
| **效能表現** | 接近原生效能 | 較慢(因為模擬硬體,效能有損耗) |
| **適用場景** | 微服務、開發/測試環境、輕量級部署 | 完整 OS 測試、執行舊系統、需要高度隔離的應用 |
| **檔案大小** | 小(通常為數十到數百 MB) | 大(通常為數 GB) |
| **範例工具** | Docker、Podman、containerd | VirtualBox、VMware、Hyper-V |
---
## ✅ 2. Hardware → Kernel → OS → Application → VM → Docker
| 層級(Layer) | **說明(Description)** | **範例(Example)** |
| ---------------------------- | ----------------------------------------- | --------------------------- |
| **硬體(Hardware)** | 實體機器(CPU、記憶體、硬碟等) | Intel 處理器、SSD、記憶體、網路卡(NIC) |
| **核心(Kernel)** | 作業系統的核心,負責軟體與硬體之間的溝通與管理 | Linux 核心、Windows NT 核心 |
| **作業系統(Operating System)** | 完整的系統環境,包含工具、服務、程式庫與命令列/圖形介面 | Ubuntu、CentOS、Windows |
| **應用程式(Application)** | 安裝並運行於作業系統上的終端應用程式或服務 | Nginx、Node.js、VSCode |
| **虛擬機(Virtual Machine)** | 在虛擬化平台(如 Hypervisor)上模擬出來的作業系統,需包含完整核心與系統 | 在 VirtualBox 上執行的 Ubuntu VM |
| **Docker 引擎(Docker Engine)** | 容器運行時環境,利用主機的作業系統核心來隔離並執行應用程式 | Docker 執行中的 Node.js 容器 |
---
## ✅ 3. `Dockerfile` vs `docker-compose.yml` vs 設定檔(Config File)
| 比較項目 | **Dockerfile** | **docker-compose.yml** | **設定檔(Config File)** |
| ---------- | ---------------------- | ----------------------------- | ------------------------------------- |
| **主要功能** | 定義如何建立一個 Docker 映像檔 | 定義並管理多個容器服務的運作方式 | 提供應用程式所需的環境變數或設定值 |
| **用途** | 建立自訂的映像檔(image) | 啟動並串接多個容器(如 Web + DB) | 控制應用程式的行為(例如資料庫主機、連接埠) |
| **檔案格式** | Docker 專屬語法 | YAML 格式 | 通常為 `.env`、`.json`、`.yaml`、`.ini` 等格式 |
| **由誰讀取使用** | Docker Engine | Docker Compose 工具 | 應用程式本身(或透過 Compose 轉給容器) |
| **關係說明** | 是建立映像檔的「建構腳本」 | 是啟動映像檔後的「部署設定」 | 是應用程式執行時所使用的「設定資訊」 |
| **典型檔案位置** | `/project/Dockerfile` | `/project/docker-compose.yml` | `/project/.env`、`config.yaml` 等 |
| **舉例** | 安裝 Node.js,複製檔案,執行應用程式 | 啟動 web + db 並配置網路、環境變數 | `PORT=3000`、`DB_HOST=localhost` 等 |
---
## ✅ 4. Docker Image vs Docker Container vs 容器環境
| 比較項目 | **Docker 映像檔(Image)** | **Docker 容器(Container)** | **容器環境(Container Environment)** |
| -------- | ----------------------- | ------------------------------- | ------------------------------- |
| **定義** | 只讀的模板,用來建立容器 | 映像檔的運行實體,實際執行中的容器 | 容器內部的運行環境(包括檔案系統、程式庫、依賴) |
| **狀態** | 靜態、不會改變 | 動態、可啟動、停止、刪除 | 是容器內部運行時所表現出來的行為 |
| **內容包含** | 作業系統層、應用程式、依賴套件、設定檔等 | 運行中的程式、程序、記憶體狀態、網路介面等 | 用來支援應用程式的所有元件,如檔案系統、變數、服務等 |
| **可否修改** | 不可修改(如需修改需重建) | 可在執行期間暫時修改,但關閉後會消失(除非建立 volume) | 容器內的應用程式與設定會影響容器環境行為 |
| **關係** | 映像檔 → 啟動 → 容器 | 容器是映像檔的「執行版本」 | 容器環境是容器運行時所呈現的「系統樣貌」 |
| **舉例** | `node:20-alpine` 是一個映像檔 | 執行中的 `Node.js` 容器 | 容器中的 `/app` 目錄、環境變數、網路組態等 |
---
### 🎯 補充說明:
* **Dockerfile** 建立 **映像檔**
* **映像檔** 被 **docker-compose.yml** 呼叫,啟動為一個或多個 **容器**
* **容器** 在啟動時會讀取應用程式的 **設定檔(Config File)**(如 `.env`)
---