2014-07-31 20:46:18 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/docker/docker/engine"
|
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (daemon *Daemon) ContainerStart(job *engine.Job) engine.Status {
|
|
|
|
if len(job.Args) < 1 {
|
|
|
|
return job.Errorf("Usage: %s container_id", job.Name)
|
|
|
|
}
|
|
|
|
var (
|
2014-12-16 23:06:35 +00:00
|
|
|
name = job.Args[0]
|
2014-07-31 20:46:18 +00:00
|
|
|
)
|
|
|
|
|
2014-12-16 23:06:35 +00:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
|
|
|
return job.Error(err)
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 00:44:53 +00:00
|
|
|
if container.IsPaused() {
|
|
|
|
return job.Errorf("Cannot start a paused container, try unpause instead.")
|
|
|
|
}
|
|
|
|
|
2014-08-31 15:20:35 +00:00
|
|
|
if container.IsRunning() {
|
2014-07-31 20:46:18 +00:00
|
|
|
return job.Errorf("Container already started")
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no environment was set, then no hostconfig was passed.
|
2014-09-25 21:23:59 +00:00
|
|
|
// This is kept for backward compatibility - hostconfig should be passed when
|
|
|
|
// creating a container, not during start.
|
2014-07-31 20:46:18 +00:00
|
|
|
if len(job.Environ()) > 0 {
|
|
|
|
hostConfig := runconfig.ContainerHostConfigFromJob(job)
|
|
|
|
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
|
|
|
return job.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := container.Start(); err != nil {
|
2014-09-19 20:54:32 +00:00
|
|
|
container.LogEvent("die")
|
2014-07-31 20:46:18 +00:00
|
|
|
return job.Errorf("Cannot start container %s: %s", name, err)
|
|
|
|
}
|
2014-08-07 17:50:25 +00:00
|
|
|
|
2014-07-31 20:46:18 +00:00
|
|
|
return engine.StatusOK
|
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
|
2014-12-12 01:22:59 +00:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-11-03 22:57:18 +00:00
|
|
|
if err := parseSecurityOpt(container, hostConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-01-21 17:04:43 +00:00
|
|
|
|
2014-07-31 20:46:18 +00:00
|
|
|
// Register any links from the host config before starting the container
|
|
|
|
if err := daemon.RegisterLinks(container, hostConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-02-11 19:21:38 +00:00
|
|
|
|
2014-12-12 01:22:59 +00:00
|
|
|
container.hostConfig = hostConfig
|
|
|
|
container.toDisk()
|
2014-07-31 20:46:18 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|