2014-08-01 00:46:18 +04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-03-25 10:44:12 +03:00
|
|
|
"fmt"
|
2015-07-17 01:33:13 +03:00
|
|
|
"runtime"
|
2015-03-25 10:44:12 +03:00
|
|
|
|
2014-08-01 00:46:18 +04:00
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
|
)
|
|
|
|
|
2015-04-11 03:05:21 +03:00
|
|
|
func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
|
2014-12-17 02:06:35 +03:00
|
|
|
container, err := daemon.Get(name)
|
|
|
|
if err != nil {
|
2015-03-25 10:44:12 +03:00
|
|
|
return err
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
|
2015-01-15 03:44:53 +03:00
|
|
|
if container.IsPaused() {
|
2015-03-25 10:44:12 +03:00
|
|
|
return fmt.Errorf("Cannot start a paused container, try unpause instead.")
|
2015-01-15 03:44:53 +03:00
|
|
|
}
|
|
|
|
|
2014-08-31 19:20:35 +04:00
|
|
|
if container.IsRunning() {
|
2015-03-25 10:44:12 +03:00
|
|
|
return fmt.Errorf("Container already started")
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
|
2015-06-13 04:31:19 +03:00
|
|
|
if _, err = daemon.verifyContainerSettings(hostConfig, nil); err != nil {
|
2015-04-16 01:43:18 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-07-17 01:33:13 +03:00
|
|
|
// Windows does not have the backwards compatibilty issue here.
|
|
|
|
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-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
}
|
2015-04-11 03:05:21 +03:00
|
|
|
|
2014-08-01 00:46:18 +04:00
|
|
|
if err := container.Start(); err != nil {
|
2015-03-25 10:44:12 +03:00
|
|
|
return fmt.Errorf("Cannot start container %s: %s", name, err)
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
2014-08-07 21:50:25 +04:00
|
|
|
|
2015-03-25 10:44:12 +03:00
|
|
|
return nil
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|