Docker容器实现原理
Docker容器在实现上是通过namespace技术来进行进程隔离,通过cgroup技术实现容器进程可用资源的限制,当docker启动一个容器时,实际是创建了多了namespace参数的进程。


Namespace
Namespace:命名空间
作用:资源隔离
原理:namespace将内核的全局资源进行封装,使得每个namespace都有一份独立的资源,因此不同进程在各自namespace内对同一种资源使用不会相互干扰


Cgroups
Cgroups:Linux Control Group
作用:限制一个进程对系统资源的使用上限,包括CPU,内存,Block,I/O等
Cgroups还能设置进程优先级,对进程进行挂起和恢复操作。
原理:将一组进程放在一个Cgroup中,通过给这个Cgroup分配指定的可用资源,达到控制这一组进程可用的目的,
实现:再Linux中,Cgroup以文件和目录的方式组织在操作系统的/sys/fs/cgroup路径下,该路径中所有的资源种类均可被cgroup限制。

CPU资源限制


内存资源限制

容器可以使用的内存资源包括内存这swap资源
BlockIO限制

|