Skip to content

Commit 3ebd928

Browse files
authored
Update docker errors (#896)
1 parent aa7572b commit 3ebd928

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

cli/cmd/errors.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package cmd
1919
import (
2020
"fmt"
2121
"net/url"
22+
"runtime"
2223
"strings"
2324

2425
"github.com/cortexlabs/cortex/pkg/lib/errors"
@@ -43,7 +44,8 @@ func getCloudFormationURL(clusterName, region string) string {
4344
const (
4445
ErrCLINotConfigured = "cli.cli_not_configured"
4546
ErrCortexYAMLNotFound = "cli.cortex_yaml_not_found"
46-
ErrDockerDaemon = "cli.docker_daemon"
47+
ErrConnectToDockerDaemon = "cli.connect_to_docker_daemon"
48+
ErrDockerPermissions = "cli.docker_permissions"
4749
ErrDockerCtrlC = "cli.docker_ctrl_c"
4850
ErrAPINotReady = "cli.api_not_ready"
4951
ErrFailedToConnectOperator = "cli.failed_to_connect_operator"
@@ -88,10 +90,29 @@ func ErrorCortexYAMLNotFound() error {
8890
})
8991
}
9092

91-
func ErrorDockerDaemon() error {
93+
func ErrorConnectToDockerDaemon() error {
94+
installMsg := "install it by following the instructions for your operating system: https://docs.docker.com/install"
95+
if strings.HasPrefix(runtime.GOOS, "darwin") {
96+
installMsg = "install it here: https://docs.docker.com/docker-for-mac/install"
97+
}
98+
99+
return errors.WithStack(&errors.Error{
100+
Kind: ErrConnectToDockerDaemon,
101+
Message: fmt.Sprintf("unable to connect to the Docker daemon\n\nplease confirm Docker is running, or if Docker is not installed, %s", installMsg),
102+
})
103+
}
104+
105+
func ErrorDockerPermissions(err error) error {
106+
errStr := errors.Message(err)
107+
108+
var groupAddStr string
109+
if strings.HasPrefix(runtime.GOOS, "linux") {
110+
groupAddStr = " (e.g. by running `sudo groupadd docker && sudo gpasswd -a $USER docker`)"
111+
}
112+
92113
return errors.WithStack(&errors.Error{
93-
Kind: ErrDockerDaemon,
94-
Message: "unable to connect to the Docker daemon, please confirm Docker is running",
114+
Kind: ErrDockerPermissions,
115+
Message: errStr + "\n\nyou can re-run this command with `sudo`, or grant your current user access to docker" + groupAddStr,
95116
})
96117
}
97118

cli/cmd/lib_manager.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ func getDockerClient() (*dockerclient.Client, error) {
6060

6161
func wrapDockerError(err error) error {
6262
if dockerclient.IsErrConnectionFailed(err) {
63-
return ErrorDockerDaemon()
63+
return ErrorConnectToDockerDaemon()
64+
}
65+
66+
if strings.Contains(strings.ToLower(err.Error()), "permission denied") {
67+
return ErrorDockerPermissions(err)
6468
}
6569

6670
return errors.WithStack(err)

0 commit comments

Comments
 (0)