本文是对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等都在这里完成设置。
其中还是很多复杂的业务逻辑,需要读者跟着代码深入去研究,这里只是抛砖引玉。