2014-08-01 00:46:18 +04:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2015-07-17 01:33:13 +03:00
|
|
|
"runtime"
|
2015-03-25 10:44:12 +03:00
|
|
|
|
2015-09-11 01:01:18 +03:00
|
|
|
"github.com/docker/docker/context"
|
2015-09-17 21:54:14 +03:00
|
|
|
derr "github.com/docker/docker/errors"
|
2014-08-01 00:46:18 +04:00
|
|
|
"github.com/docker/docker/runconfig"
|
2015-09-16 21:56:26 +03:00
|
|
|
"github.com/docker/docker/utils"
|
2014-08-01 00:46:18 +04:00
|
|
|
)
|
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
// ContainerStart starts a container.
|
2015-09-11 01:01:18 +03:00
|
|
|
func (daemon *Daemon) ContainerStart(ctx context.Context, name string, hostConfig *runconfig.HostConfig) error {
|
|
|
|
container, err := daemon.Get(ctx, name)
|
2014-12-17 02:06:35 +03:00
|
|
|
if err != nil {
|
2015-03-25 10:44:12 +03:00
|
|
|
return err
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:01:53 +03:00
|
|
|
if container.isPaused() {
|
2015-09-16 21:56:26 +03:00
|
|
|
return derr.ErrorCodeStartPaused
|
2015-01-15 03:44:53 +03:00
|
|
|
}
|
|
|
|
|
2014-08-31 19:20:35 +04:00
|
|
|
if container.IsRunning() {
|
2015-09-16 21:56:26 +03:00
|
|
|
return derr.ErrorCodeAlreadyStarted
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
|
2015-08-08 01:24:18 +03:00
|
|
|
// Windows does not have the backwards compatibility issue here.
|
2015-07-17 01:33:13 +03: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 {
|
2015-09-11 01:01:18 +03:00
|
|
|
if err := daemon.setHostConfig(ctx, container, hostConfig); err != nil {
|
2015-07-17 01:33:13 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if hostConfig != nil {
|
2015-09-16 21:56:26 +03:00
|
|
|
return derr.ErrorCodeHostConfigStart
|
2014-08-01 00:46:18 +04:00
|
|
|
}
|
|
|
|
}
|
2015-04-11 03:05:21 +03:00
|
|
|
|
2015-08-06 14:55:56 +03:00
|
|
|
// check if hostConfig is in line with the current system settings.
|
|
|
|
// It may happen cgroups are umounted or the like.
|
2015-09-11 01:01:18 +03:00
|
|
|
if _, err = daemon.verifyContainerSettings(ctx, container.hostConfig, nil); err != nil {
|
2015-08-06 14:55:56 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-09-11 01:01:18 +03:00
|
|
|
if err := container.Start(ctx); err != nil {
|
2015-09-16 21:56:26 +03:00
|
|
|
return derr.ErrorCodeCantStart.WithArgs(name, utils.GetErrorMessage(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
|
|
|
}
|