> For the complete documentation index, see [llms.txt](https://philipzheng.gitbook.io/docker_practice/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://philipzheng.gitbook.io/docker_practice/underly.md).

# 底層實作

Docker 底層的核心技術包括 Linux 上的命名空間（Namespaces）、控制組（Control groups）、Union 檔案系統（Union file systems）和容器格式（Container format）。

我們知道，傳統的虛擬機透過在宿主主機中執行 hypervisor 來模擬一整套完整的硬體環境提供給虛擬機的作業系統。虛擬機系統看到的環境是可限制的，也是彼此隔離的。 這種直接的做法實作了對資源最完整的封裝，但很多時候往往意味著系統資源的浪費。 例如，以宿主機和虛擬機系統都為 Linux 系統為例，虛擬機中執行的應用其實可以利用宿主機系統中的執行環境。

我們知道，在作業系統中，包括核心、檔案系統、網路、PID、UID、IPC、記憶體、硬盤、CPU 等等，所有的資源都是應用程式直接共享的。 要想實作虛擬化，除了要實作對記憶體、CPU、網路 IO、硬盤 IO、儲存空間等的限制外，還要實作檔案系統、網路、PID、UID、IPC 等等的相互隔離。

前者相對容易實作一些，後者則需要宿主機系統的深入支援。

隨著 Linux 系統對於命名空間功能的完善實作，程式員已經可以實作上面的所有需求，讓某些程式在彼此隔離的命名空間中執行。大家雖然都共用一個核心和某些執行時環境（例如一些系統命令和系統函式庫），但是彼此卻看不到，都以為系統中只有自己的存在。這種機制就是容器（Container），利用命名空間來做權限的隔離控制，利用 cgroups 來做資源分配。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://philipzheng.gitbook.io/docker_practice/underly.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
