本文是对runC源码的核心部分——Create Command & Run Command 进行源码分析。
对应的code workflow如下所示:
you should make sence these points:
- runC create command 和 run command的流程入口统一从/runc/utils_linux.go#334 main.startContainer方法,通过create flag进行区分。
- 业务逻辑中,主要有两个step构成:
- firstly create container filesystem and construct a linuxcontainer object by creatContainer function.
- secondly start process in container by runner.run function.
- 主要的逻辑在process的启动过程,注意以下几点:
- 对于namespace的隔离,主要通过bootstrapData封装好clone flags。
- 由sendconfig将bootstrapData封装的config传给容器起的init process。
- 调用系统setns进行namespace和process 的associate。
- oom_score_adj and rlimits等都在这里完成设置。
其中还是很多复杂的业务逻辑,需要读者跟着代码深入去研究,这里只是抛砖引玉。

本文详细解析了runC源码中的CreateCommand&RunCommand流程。从main.startContainer方法开始,通过createflag区分create和run操作。主要包括创建容器文件系统及初始化Linux容器对象,启动容器内的进程。涉及namespace隔离、配置传递及进程关联等关键技术。

1万+

被折叠的 条评论
为什么被折叠?



