forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.go
139 lines (113 loc) · 3.94 KB
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package errors
import (
"fmt"
"os/exec"
"runtime"
)
// ErrNoDockerClient is thrown when a Docker client cannot be obtained or cannot be pinged
func ErrNoDockerClient(err error) error {
return NewError("cannot obtain a Docker client").WithCause(err).WithSolution(noDockerClientSolution())
}
func ErrNoDockerMachineClient(name string, err error) error {
return NewError("cannot obtain a client for Docker machine %q", name).WithCause(err).WithSolution(noDockerMachineClientSolution())
}
func ErrCannotPingDocker(err error) error {
return NewError("cannot communicate with Docker").WithCause(err).WithSolution(noDockerClientSolution())
}
// ErrNoInsecureRegistryArgument is thrown when an --insecure-registry argument cannot be detected
// on the Docker daemon process
func ErrNoInsecureRegistryArgument() error {
return NewError("did not detect an --insecure-registry argument on the Docker daemon").WithSolution(noInsecureRegistryArgSolution())
}
const (
NoDockerMacSolution = `
Please install Docker tools by following instructions at:
https://docs.docker.com/mac/
Once installed, run this command with the --create-machine
argument to create a new Docker machine that will run OpenShift.
`
NoDockerMachineMacSolution = `
To create a new Docker machine to run OpenShift, run this command again with
the --create-machine argument. This will create a Docker machine named
'openshift'.
To use a different machine name, specify the --machine-name=NAME argument.
If you wish to use an existing Docker machine, enable it before running this
command by executing:
eval $(docker-machine env NAME)
where NAME is the name of your Docker machine.
`
NoDockerWindowsSolution = `
Please install Docker tools by following instructions at:
https://docs.docker.com/windows/
Once installed, run this command with the --create-machine argument to create a
new Docker machine that will run OpenShift.
`
NoDockerMachineWindowsSolution = `
To create a new Docker machine to run OpenShift, run this command again with
the --create-machine argument. This will create a Docker machine named
'openshift'.
To use a different machine name, specify the --machine-name=NAME argument.
If you wish to use an existing Docker machine, enable it before running this
command by executing:
docker-machine env
where NAME is the name of your Docker machine.
`
NoDockerLinuxSolution = `
Ensure that Docker is installed and accessible in your environment.
Use your package manager or follow instructions at:
https://docs.docker.com/linux/
`
NoDockerMachineClientSolution = `
Ensure that the Docker machine is available and running. You can also create a
new Docker machine by specifying the --create-machine flag.
`
NoInsecureRegistryArgSolution = `
Ensure that the Docker daemon is running with the following argument:
--insecure-registry 172.30.0.0/16
`
NoInsecureRegistryArgSolutionDockerMachine = NoInsecureRegistryArgSolution + `
You can run this command with --create-machine to create a machine with the
right argument.
`
)
func hasDockerMachine() bool {
binary := "docker-machine"
if runtime.GOOS == "windows" {
binary += ".exe"
}
_, err := exec.LookPath(binary)
return err == nil
}
func noDockerClientSolution() string {
switch runtime.GOOS {
case "darwin":
if hasDockerMachine() {
return NoDockerMachineMacSolution
}
return NoDockerMacSolution
case "windows":
if hasDockerMachine() {
return NoDockerMachineWindowsSolution
}
return NoDockerWindowsSolution
case "linux":
return NoDockerLinuxSolution
}
return fmt.Sprintf("Platform %s is not supported by this command", runtime.GOOS)
}
func noDockerMachineClientSolution() string {
return NoDockerMachineClientSolution
}
func noInsecureRegistryArgSolution() string {
switch runtime.GOOS {
case "darwin":
if hasDockerMachine() {
return NoInsecureRegistryArgSolutionDockerMachine
}
case "windows":
if hasDockerMachine() {
return NoInsecureRegistryArgSolutionDockerMachine
}
}
return NoInsecureRegistryArgSolution
}