給自己掌握的容器技術進行一次梳理
容器底層核心技術與實現原理
- Namespaces
-
- 說明
命名空間(namespaces)是 Linux 爲我們提供的用於分離進程樹、網絡接口、掛載點以及進程間通信等資源的方法。在日常使用 Linux 或者 macOS 時,我們並沒有運行多個完全分離的服務器的需要,但是如果我們在服務器上啓動了多個服務,這些服務其實會相互影響的,每一個服務都能看到其他服務的進程,也可以訪問宿主機器上的任意文件,這是很多時候我們都不願意看到的,我們更希望運行在同一臺機器上的不同服務能做到完全隔離,就像運行在多臺不同的機器上一樣。
- 說明
-
- 隔離資源列表
名稱 | 宏定義 | 隔離資源 |
---|---|---|
Mount | CLONE_NEWNS | Mount points (since Linux 2.4.19) |
UTS | CLONE_NEWUTS | Hostname and NIS domain name (since Linux 2.6.19) |
IPC | CLONE_NEWIPC | System V IPC, POSIX message queues (since Linux 2.6.19) |
Network | CLONE_NEWNET | Network devices, stacks, ports, etc. (since Linux 2.6.24) |
PID | CLONE_NEWPID | Process IDs (since Linux 2.6.24) |
User | CLONE_NEWUSER | User and group IDs (started in Linux 2.6.23 and completed in Linux 3.8) |
Cgroup | CLONE_NEWCGROUP | Cgroup root directory (since Linux 4.6) |
-
- 源碼分析
參考
- 源碼分析
struct nsproxy {
atomic_t count;
struct uts_namespace *uts_ns; // 包括user_namespace
struct ipc_namespace *ipc_ns;
struct mnt_namespace *mnt_ns;
struct pid_namespace *pid_ns_for_children;
struct net *net_ns;
struct cgroup_namespace *cgroup_ns;
};
-
- linux 演示
- linux 演示