2014-07-31 16:46:18 -04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-03-25 03:44:12 -04:00
|
|
|
"fmt"
|
|
|
|
|
2014-07-31 16:46:18 -04:00
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-04-10 20:05:21 -04:00
|
|
|
func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
|
2014-12-16 18:06:35 -05:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-07-31 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
2015-01-14 19:44:53 -05:00
|
|
|
if container.IsPaused() {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Cannot start a paused container, try unpause instead.")
|
2015-01-14 19:44:53 -05:00
|
|
|
}
|
|
|
|
|
2014-08-31 11:20:35 -04:00
|
|
|
if container.IsRunning() {
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Container already started")
|
2014-07-31 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
2015-04-15 18:43:18 -04:00
|
|
|
if _, err = daemon.verifyHostConfig(hostConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:23:59 -04:00
|
|
|
// This is kept for backward compatibility - hostconfig should be passed when
|
|
|
|
// creating a container, not during start.
|
2015-04-10 20:05:21 -04:00
|
|
|
if hostConfig != nil {
|
2014-07-31 16:46:18 -04:00
|
|
|
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
2015-03-25 03:44:12 -04:00
|
|
|
return err
|
2014-07-31 16:46:18 -04:00
|
|
|
}
|
|
|
|
}
|
2015-04-10 20:05:21 -04:00
|
|
|
|
2014-07-31 16:46:18 -04:00
|
|
|
if err := container.Start(); err != nil {
|
2014-09-19 16:54:32 -04:00
|
|
|
container.LogEvent("die")
|
2015-03-25 03:44:12 -04:00
|
|
|
return fmt.Errorf("Cannot start container %s: %s", name, err)
|
2014-07-31 16:46:18 -04:00
|
|
|
}
|
2014-08-07 13:50:25 -04:00
|
|
|
|
2015-03-25 03:44:12 -04:00
|
|
|
return nil
|
2014-07-31 16:46:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
|
2014-12-11 20:22:59 -05:00
|
|
|
container.Lock()
|
|
|
|
defer container.Unlock()
|
2014-11-03 17:57:18 -05:00
|
|
|
if err := parseSecurityOpt(container, hostConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-01-21 12:04:43 -05:00
|
|
|
|
2014-07-31 16:46:18 -04: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 14:21:38 -05:00
|
|
|
|
2014-12-11 20:22:59 -05:00
|
|
|
container.hostConfig = hostConfig
|
|
|
|
container.toDisk()
|
2014-07-31 16:46:18 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|