Merge pull request #23129 from WeiZhang555/print-detailed-error

Print original error for `start`
This commit is contained in:
Vincent Demeester 2016-06-06 13:43:52 +02:00
commit 9d449d89f7
2 changed files with 18 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"runtime"
"strings"
"syscall"
"golang.org/x/net/context"
@ -315,18 +316,18 @@ func reportError(stderr io.Writer, name string, str string, withHelp bool) {
fmt.Fprintf(stderr, "%s: %s.\n", os.Args[0], str)
}
// if container start fails with 'command not found' error, return 127
// if container start fails with 'command cannot be invoked' error, return 126
// if container start fails with 'not found'/'no such' error, return 127
// if container start fails with 'permission denied' error, return 126
// return 125 for generic docker daemon failures
func runStartContainerErr(err error) error {
trimmedErr := strings.TrimPrefix(err.Error(), "Error response from daemon: ")
statusError := cli.StatusError{StatusCode: 125}
if strings.HasPrefix(trimmedErr, "Container command") {
if strings.Contains(trimmedErr, errCmdNotFound) {
statusError = cli.StatusError{StatusCode: 127}
} else if strings.Contains(trimmedErr, errCmdCouldNotBeInvoked) {
statusError = cli.StatusError{StatusCode: 126}
}
if strings.Contains(trimmedErr, "executable file not found") ||
strings.Contains(trimmedErr, "no such file or directory") ||
strings.Contains(trimmedErr, "system cannot find the file specified") {
statusError = cli.StatusError{StatusCode: 127}
} else if strings.Contains(trimmedErr, syscall.EACCES.Error()) {
statusError = cli.StatusError{StatusCode: 126}
}
return statusError

View File

@ -7,6 +7,8 @@ import (
"strings"
"syscall"
"google.golang.org/grpc"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/container"
"github.com/docker/docker/errors"
@ -131,24 +133,24 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
}
if err := daemon.containerd.Create(container.ID, *spec, libcontainerd.WithRestartManager(container.RestartManager(true))); err != nil {
errDesc := grpc.ErrorDesc(err)
logrus.Errorf("Create container failed with error: %s", errDesc)
// if we receive an internal error from the initial start of a container then lets
// return it instead of entering the restart loop
// set to 127 for container cmd not found/does not exist)
if strings.Contains(err.Error(), "executable file not found") ||
strings.Contains(err.Error(), "no such file or directory") ||
strings.Contains(err.Error(), "system cannot find the file specified") {
if strings.Contains(errDesc, "executable file not found") ||
strings.Contains(errDesc, "no such file or directory") ||
strings.Contains(errDesc, "system cannot find the file specified") {
container.ExitCode = 127
err = fmt.Errorf("Container command '%s' not found or does not exist", container.Path)
}
// set to 126 for container cmd can't be invoked errors
if strings.Contains(err.Error(), syscall.EACCES.Error()) {
if strings.Contains(errDesc, syscall.EACCES.Error()) {
container.ExitCode = 126
err = fmt.Errorf("Container command '%s' could not be invoked", container.Path)
}
container.Reset(false)
return err
return fmt.Errorf("%s", errDesc)
}
return nil