Skip to content

Update docker errors #896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions cli/cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"fmt"
"net/url"
"runtime"
"strings"

"github.com/cortexlabs/cortex/pkg/lib/errors"
Expand All @@ -43,7 +44,8 @@ func getCloudFormationURL(clusterName, region string) string {
const (
ErrCLINotConfigured = "cli.cli_not_configured"
ErrCortexYAMLNotFound = "cli.cortex_yaml_not_found"
ErrDockerDaemon = "cli.docker_daemon"
ErrConnectToDockerDaemon = "cli.connect_to_docker_daemon"
ErrDockerPermissions = "cli.docker_permissions"
ErrDockerCtrlC = "cli.docker_ctrl_c"
ErrAPINotReady = "cli.api_not_ready"
ErrFailedToConnectOperator = "cli.failed_to_connect_operator"
Expand Down Expand Up @@ -88,10 +90,29 @@ func ErrorCortexYAMLNotFound() error {
})
}

func ErrorDockerDaemon() error {
func ErrorConnectToDockerDaemon() error {
installMsg := "install it by following the instructions for your operating system: https://docs.docker.com/install"
if strings.HasPrefix(runtime.GOOS, "darwin") {
installMsg = "install it here: https://docs.docker.com/docker-for-mac/install"
}

return errors.WithStack(&errors.Error{
Kind: ErrConnectToDockerDaemon,
Message: fmt.Sprintf("unable to connect to the Docker daemon\n\nplease confirm Docker is running, or if Docker is not installed, %s", installMsg),
})
}

func ErrorDockerPermissions(err error) error {
errStr := errors.Message(err)

var groupAddStr string
if strings.HasPrefix(runtime.GOOS, "linux") {
groupAddStr = " (e.g. by running `sudo groupadd docker && sudo gpasswd -a $USER docker`)"
}

return errors.WithStack(&errors.Error{
Kind: ErrDockerDaemon,
Message: "unable to connect to the Docker daemon, please confirm Docker is running",
Kind: ErrDockerPermissions,
Message: errStr + "\n\nyou can re-run this command with `sudo`, or grant your current user access to docker" + groupAddStr,
})
}

Expand Down
6 changes: 5 additions & 1 deletion cli/cmd/lib_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ func getDockerClient() (*dockerclient.Client, error) {

func wrapDockerError(err error) error {
if dockerclient.IsErrConnectionFailed(err) {
return ErrorDockerDaemon()
return ErrorConnectToDockerDaemon()
}

if strings.Contains(strings.ToLower(err.Error()), "permission denied") {
return ErrorDockerPermissions(err)
}

return errors.WithStack(err)
Expand Down