mirror of https://github.com/docker/docs.git
Merge pull request #8990 from duglin/Issue8379a
Make sure that if a container can't start we set the exitcode to non-zero value
This commit is contained in:
commit
a72f3c568b
|
@ -302,6 +302,10 @@ func (container *Container) Start() (err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
container.setError(err)
|
container.setError(err)
|
||||||
|
// if no one else has set it, make sure we don't leave it at zero
|
||||||
|
if container.ExitCode == 0 {
|
||||||
|
container.ExitCode = 128
|
||||||
|
}
|
||||||
container.toDisk()
|
container.toDisk()
|
||||||
container.cleanup()
|
container.cleanup()
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,6 +138,7 @@ func (m *containerMonitor) Start() error {
|
||||||
// if we receive an internal error from the initial start of a container then lets
|
// if we receive an internal error from the initial start of a container then lets
|
||||||
// return it instead of entering the restart loop
|
// return it instead of entering the restart loop
|
||||||
if m.container.RestartCount == 0 {
|
if m.container.RestartCount == 0 {
|
||||||
|
m.container.ExitCode = exitStatus
|
||||||
m.resetContainer(false)
|
m.resetContainer(false)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -163,10 +164,12 @@ func (m *containerMonitor) Start() error {
|
||||||
// we need to check this before reentering the loop because the waitForNextRestart could have
|
// we need to check this before reentering the loop because the waitForNextRestart could have
|
||||||
// been terminated by a request from a user
|
// been terminated by a request from a user
|
||||||
if m.shouldStop {
|
if m.shouldStop {
|
||||||
|
m.container.ExitCode = exitStatus
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
m.container.ExitCode = exitStatus
|
||||||
m.container.LogEvent("die")
|
m.container.LogEvent("die")
|
||||||
m.resetContainer(true)
|
m.resetContainer(true)
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -2538,3 +2538,33 @@ func TestRunAllowPortRangeThroughExpose(t *testing.T) {
|
||||||
}
|
}
|
||||||
logDone("run - allow port range through --expose flag")
|
logDone("run - allow port range through --expose flag")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunUnknownCommand(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
runCmd := exec.Command(dockerBinary, "create", "busybox", "/bin/nada")
|
||||||
|
cID, _, _, err := runCommandWithStdoutStderr(runCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to create container: %v, output: %q", err, cID)
|
||||||
|
}
|
||||||
|
cID = strings.TrimSpace(cID)
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "start", cID)
|
||||||
|
_, _, _, err = runCommandWithStdoutStderr(runCmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Container should not have been able to start!")
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "inspect", "--format={{.State.ExitCode}}", cID)
|
||||||
|
rc, _, _, err2 := runCommandWithStdoutStderr(runCmd)
|
||||||
|
rc = strings.TrimSpace(rc)
|
||||||
|
|
||||||
|
if err2 != nil {
|
||||||
|
t.Fatalf("Error getting status of container: %v", err2)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rc != "-1" {
|
||||||
|
t.Fatalf("ExitCode(%v) was supposed to be -1", rc)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("run - Unknown Command")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue