runC源码分析——Create/Run Container

来源:互联网 发布:java进程同步编程 编辑:程序博客网 时间:2024/05/18 03:02

本文是对runC源码的核心部分——Create Command & Run Command 进行源码分析。

对应的code workflow如下所示:
这里写图片描述

you should make sence these points:

  1. runC create command 和 run command的流程入口统一从/runc/utils_linux.go#334 main.startContainer方法,通过create flag进行区分。
  2. 业务逻辑中,主要有两个step构成:
    • firstly create container filesystem and construct a linuxcontainer object by creatContainer function.
    • secondly start process in container by runner.run function.
  3. 主要的逻辑在process的启动过程,注意以下几点:
    • 对于namespace的隔离,主要通过bootstrapData封装好clone flags。
    • 由sendconfig将bootstrapData封装的config传给容器起的init process。
    • 调用系统setns进行namespace和process 的associate。
    • oom_score_adj and rlimits等都在这里完成设置。

其中还是很多复杂的业务逻辑,需要读者跟着代码深入去研究,这里只是抛砖引玉。

1 0
原创粉丝点击