runc start container流程分析
1、runc/start.go
Action: func(context *cli.Context) error
该函数首先调用container, err := getContainer(context)获取container信息,接着调用status, err := container.Status()获取容器的当前状态。最后,如果status为libcontainer.Created,则调用container.Exec()在创建的容器内执行用户定义的进程。若status为libcontainer.Stopped,则报错,因为runc不能start一个已经run并且stop了的容器,其他状况则都报错。
--------------------------------------------------------------------------------获取容器实例-----------------------------------------------------------------------------------------------
2、runc/utils_linux.go
// getContainer returns the specified container instance by loading it from state with the default factory
func getContainer(context *cli.Context) (libcontainer.Container, error)
首先调用 id := context.Args().First()获取容器id,再调用factory, err := loadFactory(context)获取默认工厂实例,最后,return factory.Load(id)返回容器实例。
3、runc.utils_linux.go
// loadFactory returns the configured factory instance for execing containers
获取存储容器信息的目录abs,一般为/run/runc/,获取cgroupManager,最后调用return libcontainer.New(abs, cgroupManager, libcontainer.CriuPath(context.GlobalString("criu")))返回默认factory实例。(详细的描述参见《runc create container流程分析》)
4、runc/libcontainer/factory_linux.go
func (l *LinuxFactory) Load(id string) (Container, error)
调用containerRoot := filepath.Join(l.Root, id)获取容器目录(一般为/run/runc/container-id)。再调用state, err := l.loadState(containerRoot, id)加载容器状态(即加载/run/runc/container-id/state.json)。接着根据配置文件填充获得process和container,如下所示:
r := &nonchildProcess {
processPid: state.InitProcessPid,
processStartTime: state.InitProcessStartTime,
fds: state.ExternalDescriptors,
}
c := &linuxContainer {
initProcess: r,
initProcessStartTime: state.InitProcessStartTime,
id: id,
config: &state.Config,
initArgs: l.InitArgs,
criuPath: l.CriuPath,
cgroupManager: l.NewCgroupsManager(state.Config.Cgroups, state.CgroupPaths)
root: containerRoot,
created: state.Created,
}
c.state = &loadedState{c: c}
最后c.refreshState()
------------------------------------------------------------------------------结束容器实例获取----------------------------------------------------------------------------------------
5、runc/libcontainer/container_linux.go
func (c *linuxContainer) exec() error
获取容器实例之后,其实只要打开/run/runc/container-id/exec.fifo文件,通知之前已经创建的容器可以开始执行用户进程了。然后再从fifo文件中,获取一个字节的同步数据,最后删除fifo文件,容器start 完成。
注:runc run命令与runc create & start的不同之处在于run命令在容器创建完成之后,就直接调用c.exec()启动容器内的用户进程,而create & start是把c.exec单独划分至start命令当中。
runc start container流程分析的更多相关文章
- runc create container 流程分析
1.// runc/create.go Action: func(context *cli.Context) error 首先调用spec, err := setupSpec(context)加载配置 ...
- runv start container 流程分析
1.runv/start.go func startContainer(context *cli.Context, container, address string, config *spec.Sp ...
- spark 启动job的流程分析
从WordCount開始分析 编写一个样例程序 编写一个从HDFS中读取并计算wordcount的样例程序: packageorg.apache.spark.examples importorg.ap ...
- 8、Struts2 运行流程分析
1.流程分析: 请求发送给 StrutsPrepareAndExecuteFilter StrutsPrepareAndExecuteFilter 询问 ActionMapper: 该请求是否是一个 ...
- freeswitch呼叫流程分析
今天翻文档时发现之前整理的关于freeswitch呼叫相关的内容,写成博文分享出来也方便我以后查阅. 整体结构图 FreeswitchCore 模块加载过程 freeswitch主程序初始化时会从mo ...
- u-boot 流程分析
u-boot 介绍: 对于计算机来说 , 从一开始上机通电是无法直接启动操作系统的 , 这中间需要一个引导过程 , 嵌入式Linux系统同样离不开引导程序 , 这个启动程序就叫启动加载程序(Boot ...
- thttpd和cgilua安装与运行流程分析
安装 参考如下博文安装thttpd软件 http://blog.csdn.net/21aspnet/article/details/7045845 http://blog.csdn.net/drago ...
- 【转】Hostapd工作流程分析
[转]Hostapd工作流程分析 转自:http://blog.chinaunix.net/uid-30081165-id-5290531.html Hostapd是一个运行在用户态的守护进程,可以通 ...
- u-boot中nandflash初始化流程分析(转)
u-boot中nandflash初始化流程分析(转) 原文地址http://zhuairlunjj.blog.163.com/blog/static/80050945201092011249136/ ...
随机推荐
- 重新想象 Windows 8 Store Apps (60) - 通信: 获取网络信息, 序列化和反序列化
[源码下载] 重新想象 Windows 8 Store Apps (60) - 通信: 获取网络信息, 序列化和反序列化 作者:webabcd 介绍重新想象 Windows 8 Store Apps ...
- KMP--Cyclic Nacklace
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110060#problem/D Description CC always be ...
- 非线性数据拟合-nls
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
- Afinal
1.注解功能 1)继承:FinalActivity ( 需要复制 afinal_0.5.1_bin.jar到lib下) 2)@ViewInject() public class AfinalActiv ...
- 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的
声明:本文不对爆吧行为及其涉及的事件进行是非判断,只探讨帝吧文化本身,欢迎拍砖.更正和补充. 一.“帝吧FB出征”事件梳理 继上次全网集体骂 “薯片”事件后,昨日(1月20日)晚7点,又发生了一次互联 ...
- OC静态库里NSClassFromString得到nil的解决
如果你在静态库中有从类名反射回类的代码, 如下: NSString *myClassStr = @"myClass"; Class myClazz = NSClassFromStr ...
- 2015第18本:从0到1,ZERO to ONE, Notes on startups, or how to build the future
<从0到1>中文版的副标题是”开创商业与未来的秘密“,题目大得吓人,英文副标题就谨慎了许多:Notes on startups, or how to build the future. 全 ...
- android view holder 优化
android 一般都用viewholder来优化contentView,采用sparseArray能够进一步优化 /** * 用法: ImageView bananaView = ViewHolde ...
- Android SDK Manager 在win8.1上的闪退问题
全新安装的Windows 8.1的系统,Android SDK,JDK都是最新的版本,但是SDK Manager打开是命令行窗口一闪而过,就再没反映了. 通过搜索,确定了一个问题就是SDK目录tool ...
- OC中结构体作为对象属性
在OC中结构体有时候也作为对象的属性 类的定义 #import <Foundation/Foundation.h> typedef struct{ int year; int month; ...