Merge pull request #11570 from runcom/9658-consistent-autoremove

Remove container if --rm flag is passed and container cannot be started
This commit is contained in:
Alexander Morozov
2015-03-23 15:38:51 -07:00
2 changed files with 51 additions and 3 deletions
+43
View File
@@ -3348,3 +3348,46 @@ func TestRunVolumesFromRestartAfterRemoved(t *testing.T) {
logDone("run - can restart a volumes-from container after producer is removed")
}
// run container with --rm should remove container if exit code != 0
func TestRunContainerWithRmFlagExitCodeNotEqualToZero(t *testing.T) {
defer deleteAllContainers()
runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "ls", "/notexists")
out, _, err := runCommandWithOutput(runCmd)
if err == nil {
t.Fatal("Expected docker run to fail", out, err)
}
out, err = getAllContainers()
if err != nil {
t.Fatal(out, err)
}
if out != "" {
t.Fatal("Expected not to have containers", out)
}
logDone("run - container is removed if run with --rm and exit code != 0")
}
func TestRunContainerWithRmFlagCannotStartContainer(t *testing.T) {
defer deleteAllContainers()
runCmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "commandNotFound")
out, _, err := runCommandWithOutput(runCmd)
if err == nil {
t.Fatal("Expected docker run to fail", out, err)
}
out, err = getAllContainers()
if err != nil {
t.Fatal(out, err)
}
if out != "" {
t.Fatal("Expected not to have containers", out)
}
logDone("run - container is removed if run with --rm and cannot start")
}