'docker start'执行CMD命令吗?

Jul*_*tin 15 docker

假设一个docker容器已经使用'docker run'运行,然后使用'docker stop'停止."码头开始"后是否会执行"CMD"命令?

Tra*_*der 14

我相信@jripoll不正确,它似乎运行,这是与第一次运行该命令docker rundocker start了.

这是一个简单的测试示例:

首先创建一个要运行的shell脚本tmp.sh:

echo "hello yo!"
Run Code Online (Sandbox Code Playgroud)

然后运行:

docker run --name yo -v "$(pwd)":/usr/src/myapp -w /usr/src/myapp ubuntu sh tmp.sh 
Run Code Online (Sandbox Code Playgroud)

那将打印出来hello yo!.

现在重新开始:

docker start -ia yo
Run Code Online (Sandbox Code Playgroud)

它会在每次运行时再次打印出来.


Von*_*onC 6

当您启动docker时,您会调用api/client/start.go,调用:

 cli.client.ContainerStart(containerID)
Run Code Online (Sandbox Code Playgroud)

那叫engine-api/client/container_start.go:

cli.post("/containers/"+containerID+"/start", nil, nil, nil)
Run Code Online (Sandbox Code Playgroud)

API调用的docker守护程序进程daemon/start.go:

container.StartMonitor(daemon, container.HostConfig.RestartPolicy)
Run Code Online (Sandbox Code Playgroud)

容器监视器在以下位置运行容器container/monitor.go:

m.supervisor.Run(m.container, pipes, m.callback)
Run Code Online (Sandbox Code Playgroud)

默认情况下,docker守护程序是daemon/daemon.go中的管理程序:

daemon.execDriver.Run(c.Command, pipes, hooks)
Run Code Online (Sandbox Code Playgroud)

execDriver在以下位置创建命令行daemon/execdriver/windows/exec.go:

createProcessParms.CommandLine, err = createCommandLine(processConfig, false)
Run Code Online (Sandbox Code Playgroud)

使用processConfig.Entrypoint processConfig.Argumentsdaemon/execdriver/windows/commandlinebuilder.go:

// Build the command line of the process
commandLine = processConfig.Entrypoint
logrus.Debugf("Entrypoint: %s", processConfig.Entrypoint)
for _, arg := range processConfig.Arguments {
    logrus.Debugf("appending %s", arg)
    if !alreadyEscaped {
        arg = syscall.EscapeArg(arg)
    }
    commandLine += " " + arg
}
Run Code Online (Sandbox Code Playgroud)

这些ProcessConfig.Arguments人口居住在daemon/container_operations_windows.go:

processConfig := execdriver.ProcessConfig{
    CommonProcessConfig: execdriver.CommonProcessConfig{
        Entrypoint: c.Path,
        Arguments:  c.Args,
        Tty:        c.Config.Tty,
    },
Run Code Online (Sandbox Code Playgroud)

,c.Args作为Container的参数(runtile参数或CMD)

所以是的,' CMD'命令在' '之后执行docker start.