1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/start.go
Srini Brahmaroutu 1a35b16b08 Port test from integration tests
Addresses #12255
Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
2015-04-20 17:57:53 +00:00

59 lines
1.3 KiB
Go

package daemon
import (
"fmt"
"github.com/docker/docker/runconfig"
)
func (daemon *Daemon) ContainerStart(name string, hostConfig *runconfig.HostConfig) error {
container, err := daemon.Get(name)
if err != nil {
return err
}
if container.IsPaused() {
return fmt.Errorf("Cannot start a paused container, try unpause instead.")
}
if container.IsRunning() {
return fmt.Errorf("Container already started")
}
if _, err = daemon.verifyHostConfig(hostConfig); err != nil {
return err
}
// 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
}
}
if err := container.Start(); err != nil {
container.LogEvent("die")
return fmt.Errorf("Cannot start container %s: %s", name, err)
}
return nil
}
func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.HostConfig) error {
container.Lock()
defer container.Unlock()
if err := parseSecurityOpt(container, hostConfig); err != nil {
return err
}
// Register any links from the host config before starting the container
if err := daemon.RegisterLinks(container, hostConfig); err != nil {
return err
}
container.hostConfig = hostConfig
container.toDisk()
return nil
}