2014-07-31 20:46:18 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-03-25 07:44:12 +00:00
|
|
|
"fmt"
|
2015-07-16 22:33:13 +00:00
|
|
|
"runtime"
|
2015-03-25 07:44:12 +00:00
|
|
|
|
2014-07-31 20:46:18 +00:00
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
// ContainerStart starts a container.
|
2015-04-11 00:05:21 +00:00
|
|
|
func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
|
2014-12-16 23:06:35 +00:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-03-25 07:44:12 +00:00
|
|
|
return err
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|
|
|
|
|
2015-07-30 21:01:53 +00:00
|
|
|
if container.isPaused() {
|
2015-03-25 07:44:12 +00:00
|
|
|
return fmt.Errorf("Cannot start a paused container, try unpause instead.")
|
2015-01-15 00:44:53 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 15:20:35 +00:00
|
|
|
if container.IsRunning() {
|
2015-03-25 07:44:12 +00:00
|
|
|
return fmt.Errorf("Container already started")
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|
|
|
|
|
2015-08-07 22:24:18 +00:00
|
|
|
// Windows does not have the backwards compatibility issue here.
|
2015-07-16 22:33:13 +00:00
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
// This is kept for backward compatibility - hostconfig should be passed when
|
|
|
|
// creating a container, not during start.
|
|
|
|
if hostConfig != nil {
|
|
|
|
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if hostConfig != nil {
|
|
|
|
return fmt.Errorf("Supplying a hostconfig on start is not supported. It should be supplied on create")
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-11 00:05:21 +00:00
|
|
|
|
2015-08-06 11:55:56 +00:00
|
|
|
// check if hostConfig is in line with the current system settings.
|
|
|
|
// It may happen cgroups are umounted or the like.
|
|
|
|
if _, err = daemon.verifyContainerSettings(container.hostConfig, nil); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-07-31 20:46:18 +00:00
|
|
|
if err := container.Start(); err != nil {
|
2015-03-25 07:44:12 +00:00
|
|
|
return fmt.Errorf("Cannot start container %s: %s", name, err)
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|
2014-08-07 17:50:25 +00:00
|
|
|
|
2015-03-25 07:44:12 +00:00
|
|
|
return nil
|
2014-07-31 20:46:18 +00:00
|
|
|
}
|