Fix docker start muliple containers continue on one failed and
add docker start show error message from daemon when start failed Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
faa6fd40f4
commit
2a5a50dca7
2 changed files with 63 additions and 2 deletions
|
@ -778,14 +778,18 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var encounteredError error
|
||||||
for _, name := range cmd.Args() {
|
for _, name := range cmd.Args() {
|
||||||
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/start", nil, false))
|
_, _, err := readBody(cli.call("POST", "/containers/"+name+"/start", nil, false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !*attach && !*openStdin {
|
if !*attach && !*openStdin {
|
||||||
|
// attach and openStdin is false means it could be starting multiple containers
|
||||||
|
// when a container start failed, show the error message and start next
|
||||||
fmt.Fprintf(cli.err, "%s\n", err)
|
fmt.Fprintf(cli.err, "%s\n", err)
|
||||||
|
encounteredError = fmt.Errorf("Error: failed to start one or more containers")
|
||||||
|
} else {
|
||||||
|
encounteredError = err
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Error: failed to start one or more containers")
|
|
||||||
} else {
|
} else {
|
||||||
if !*attach && !*openStdin {
|
if !*attach && !*openStdin {
|
||||||
fmt.Fprintf(cli.out, "%s\n", name)
|
fmt.Fprintf(cli.out, "%s\n", name)
|
||||||
|
@ -793,6 +797,10 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if encounteredError != nil {
|
||||||
|
return encounteredError
|
||||||
|
}
|
||||||
|
|
||||||
if *openStdin || *attach {
|
if *openStdin || *attach {
|
||||||
if tty && cli.isTerminalOut {
|
if tty && cli.isTerminalOut {
|
||||||
if err := cli.monitorTtySize(cmd.Arg(0), false); err != nil {
|
if err := cli.monitorTtySize(cmd.Arg(0), false); err != nil {
|
||||||
|
|
|
@ -187,3 +187,56 @@ func TestStartPausedContainer(t *testing.T) {
|
||||||
|
|
||||||
logDone("start - error should show if trying to start paused container")
|
logDone("start - error should show if trying to start paused container")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStartMultipleContainers(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
// run a container named 'parent' and create two container link to `parent`
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top")
|
||||||
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
for _, container := range []string{"child_first", "child_second"} {
|
||||||
|
cmd = exec.Command(dockerBinary, "create", "--name", container, "--link", "parent:parent", "busybox", "top")
|
||||||
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// stop 'parent' container
|
||||||
|
cmd = exec.Command(dockerBinary, "stop", "parent")
|
||||||
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Running}}", "parent")
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
out = strings.Trim(out, "\r\n")
|
||||||
|
if out != "false" {
|
||||||
|
t.Fatal("Container should be stopped")
|
||||||
|
}
|
||||||
|
|
||||||
|
// start all the three containers, container `child_first` start first which should be faild
|
||||||
|
// container 'parent' start second and then start container 'child_second'
|
||||||
|
cmd = exec.Command(dockerBinary, "start", "child_first", "parent", "child_second")
|
||||||
|
out, _, err = runCommandWithOutput(cmd)
|
||||||
|
if !strings.Contains(out, "Cannot start container child_first") || err == nil {
|
||||||
|
t.Fatal("Expected error but got none")
|
||||||
|
}
|
||||||
|
|
||||||
|
for container, expected := range map[string]string{"parent": "true", "child_first": "false", "child_second": "true"} {
|
||||||
|
cmd = exec.Command(dockerBinary, "inspect", "-f", "{{.State.Running}}", container)
|
||||||
|
out, _, err = runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(out, err)
|
||||||
|
}
|
||||||
|
out = strings.Trim(out, "\r\n")
|
||||||
|
if out != expected {
|
||||||
|
t.Fatal("Container running state wrong")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("start - start multiple containers continue on one failed")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue