run.go#Action
前面代码和create都一样,只是在调用runner#run时传入的操作类型为run。
case CT_ACT_CREATE:
err = r.container.Start(process)
case CT_ACT_RESTORE:
err = r.container.Restore(process, r.criuOpts)
case CT_ACT_RUN:
err = r.container.Run(process)
1) libcontainer/container_linux.go#linuxContainer.Run
BaseContainer
// Start a process inside the container. Returns error if process fails to
// start. You can track process lifecycle with passed Process structure.
//
// errors:
// ContainerNotExists - Container no longer exists,
// ConfigInvalid - config is invalid,
// ContainerPaused - Container is paused,
// SystemError - System error.
Start(process *Process) (err error)
// Run immediately starts the process inside the container. Returns error if process
// fails to start. It does not block waiting for the exec fifo after start returns but
// opens the fifo after start returns.
//
// errors:
// ContainerNotExists - Container no longer exists,
// ConfigInvalid - config is invalid,
// ContainerPaused - Container is paused,
// SystemError - System error.
Run(process *Process) (err error)
不涉及exec.fifo文件的创建与删除。
- 在Container.Start【容器CREATE】时,会在容器启动前创建exec.fifo,在容器启动完毕后删除exec.fifo,因为Start时不执行真正的命令,所以需要使用exec.fifo阻塞。
- 在容器【START】时也会使用这个文件,只读方式打开该文件,向容器Init进程发送信号,执行真正的命令。
- 在容器【RUN,即CREATE+START】时,会先执行【容器CREATE】操作,然后执行【容器RUN】操作。
func (c *linuxContainer) Run(process *Process) error {
if err := c.Start(process); err != nil {
return err
}
if process.Init {
return c.exec()
}
return nil
}