docker启动Container进程之启动流程

docker启动Container进程之启动流程


代码分析起点:daemon/container.go/Start
docker启动containter的起始点在daemon/container.go/Start方法。
这个方法做了三大方面的事情:

  • 配置启动container所需要的环境
  • 启动container进程
  • 如果container启动失败,做资源回收

1 配置启动container需要的环境

此部分为启动container进程做准备。包括一下几个方面:
1. 构建container的DNS
使用container的setupContainerDns方法构建container的DNS。 –dns
2. 挂在文件系统
使用Mount方法配置container的basefs路径。
3. 初始化网络
使用initialize方法配置container网络信息,详细分析见docker如果构建bridge网络 。–net
4. 更新parent hosts
使用container的updateParentHosts方法更新与当前container相关container的etc/hosts
5. 验证container资源设置
使用container的verifyDaemonSetting方法校验container的Me moryLimitSwapLimitIPv4ForwardingDisable设置。
6. 卷准备
使用container的prepareVolumes方法为container启动配置挂载数据卷。 –volume
7. 链接其他container
使用container的setupLinkedContainers方法配置container需要连接的其他container。 –link
8. 构建工作路径
使用container的setupWorkingDirectory方法配置container的工作路径。
9. 创建container进程环境
使用container的createDaemonEnvironment方法配置container内的环境变量。 –env
10. populateCommand
根据步骤9收集到的环境变量,使用populateCommand构建execdriver命令execdriver.Command
11. 构建mount点
使用container的setupMounts方法设置container内部的mount配置。

2 启动container进程

在准备好启动container进程的配置后,docker开始创建container进程,使用container的waitForStart方法完成此项任务。
通过为启动的container创建一个monitor来监控container进程的启动情况,这个地方使用了golang的一个特性:channel
如果container进程正常启动,那么会在container.monitor.startSigbal通道受到一个信号;如果在promise.Go(container.monitor.Start)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值