1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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" "os"
"runtime" "runtime"
"strings" "strings"
"syscall"
"golang.org/x/net/context" "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) 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 'not found'/'no such' error, return 127
// if container start fails with 'command cannot be invoked' error, return 126 // if container start fails with 'permission denied' error, return 126
// return 125 for generic docker daemon failures // return 125 for generic docker daemon failures
func runStartContainerErr(err error) error { func runStartContainerErr(err error) error {
trimmedErr := strings.TrimPrefix(err.Error(), "Error response from daemon: ") trimmedErr := strings.TrimPrefix(err.Error(), "Error response from daemon: ")
statusError := cli.StatusError{StatusCode: 125} statusError := cli.StatusError{StatusCode: 125}
if strings.HasPrefix(trimmedErr, "Container command") { if strings.Contains(trimmedErr, "executable file not found") ||
if strings.Contains(trimmedErr, errCmdNotFound) { strings.Contains(trimmedErr, "no such file or directory") ||
statusError = cli.StatusError{StatusCode: 127} strings.Contains(trimmedErr, "system cannot find the file specified") {
} else if strings.Contains(trimmedErr, errCmdCouldNotBeInvoked) { statusError = cli.StatusError{StatusCode: 127}
statusError = cli.StatusError{StatusCode: 126} } else if strings.Contains(trimmedErr, syscall.EACCES.Error()) {
} statusError = cli.StatusError{StatusCode: 126}
} }
return statusError return statusError

View file

@ -7,6 +7,8 @@ import (
"strings" "strings"
"syscall" "syscall"
"google.golang.org/grpc"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/docker/docker/container" "github.com/docker/docker/container"
"github.com/docker/docker/errors" "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 { 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 // 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
// set to 127 for container cmd not found/does not exist) // set to 127 for container cmd not found/does not exist)
if strings.Contains(err.Error(), "executable file not found") || if strings.Contains(errDesc, "executable file not found") ||
strings.Contains(err.Error(), "no such file or directory") || strings.Contains(errDesc, "no such file or directory") ||
strings.Contains(err.Error(), "system cannot find the file specified") { strings.Contains(errDesc, "system cannot find the file specified") {
container.ExitCode = 127 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 // 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 container.ExitCode = 126
err = fmt.Errorf("Container command '%s' could not be invoked", container.Path)
} }
container.Reset(false) container.Reset(false)
return err return fmt.Errorf("%s", errDesc)
} }
return nil return nil