github.com/torfuzx/docker@v1.8.1/daemon/start.go (about)

     1  package daemon
     2  
     3  import (
     4  	"fmt"
     5  	"runtime"
     6  
     7  	"github.com/docker/docker/runconfig"
     8  )
     9  
    10  func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
    11  	container, err := daemon.Get(name)
    12  	if err != nil {
    13  		return err
    14  	}
    15  
    16  	if container.IsPaused() {
    17  		return fmt.Errorf("Cannot start a paused container, try unpause instead.")
    18  	}
    19  
    20  	if container.IsRunning() {
    21  		return fmt.Errorf("Container already started")
    22  	}
    23  
    24  	if _, err = daemon.verifyContainerSettings(hostConfig, nil); err != nil {
    25  		return err
    26  	}
    27  
    28  	// Windows does not have the backwards compatibilty issue here.
    29  	if runtime.GOOS != "windows" {
    30  		// This is kept for backward compatibility - hostconfig should be passed when
    31  		// creating a container, not during start.
    32  		if hostConfig != nil {
    33  			if err := daemon.setHostConfig(container, hostConfig); err != nil {
    34  				return err
    35  			}
    36  		}
    37  	} else {
    38  		if hostConfig != nil {
    39  			return fmt.Errorf("Supplying a hostconfig on start is not supported. It should be supplied on create")
    40  		}
    41  	}
    42  
    43  	if err := container.Start(); err != nil {
    44  		return fmt.Errorf("Cannot start container %s: %s", name, err)
    45  	}
    46  
    47  	return nil
    48  }