daemon/start.go
4180b875
 package daemon
 
 import (
39ad38cc
 	"runtime"
c79b9bab
 
a283a30f
 	derr "github.com/docker/docker/errors"
4180b875
 	"github.com/docker/docker/runconfig"
f7d4b4fe
 	"github.com/docker/docker/utils"
4180b875
 )
 
abd72d40
 // ContainerStart starts a container.
b08f071e
 func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
 	container, err := daemon.Get(name)
d25a6537
 	if err != nil {
c79b9bab
 		return err
4180b875
 	}
 
abd72d40
 	if container.isPaused() {
f7d4b4fe
 		return derr.ErrorCodeStartPaused
02246d2d
 	}
 
e0339d4b
 	if container.IsRunning() {
f7d4b4fe
 		return derr.ErrorCodeAlreadyStarted
4180b875
 	}
 
51462327
 	// Windows does not have the backwards compatibility issue here.
39ad38cc
 	if runtime.GOOS != "windows" {
 		// This is kept for backward compatibility - hostconfig should be passed when
 		// creating a container, not during start.
 		if hostConfig != nil {
b08f071e
 			if err := daemon.setHostConfig(container, hostConfig); err != nil {
39ad38cc
 				return err
 			}
 		}
 	} else {
 		if hostConfig != nil {
f7d4b4fe
 			return derr.ErrorCodeHostConfigStart
4180b875
 		}
 	}
767df67e
 
4177b0ba
 	// check if hostConfig is in line with the current system settings.
 	// It may happen cgroups are umounted or the like.
b08f071e
 	if _, err = daemon.verifyContainerSettings(container.hostConfig, nil); err != nil {
4177b0ba
 		return err
 	}
 
b08f071e
 	if err := container.Start(); err != nil {
f7d4b4fe
 		return derr.ErrorCodeCantStart.WithArgs(name, utils.GetErrorMessage(err))
4180b875
 	}
6ae05936
 
c79b9bab
 	return nil
4180b875
 }