MCPcopy
hub / github.com/cubefs/cubefs / checkAndInstallDocker

Function checkAndInstallDocker

deploy/cmd/docker.go:118–141  ·  view source on GitHub ↗

Check if Docker is installed and installed

(nodeUser, node string)

Source from the content-addressed store, hash-verified

116
117// Check if Docker is installed and installed
118func checkAndInstallDocker(nodeUser, node string) error {
119 // Check if Docker is installed
120 cmd := exec.Command("ssh", nodeUser+"@"+node, "docker --version")
121 output, err := cmd.Output()
122 if err == nil && strings.Contains(string(output), "Docker version") {
123 // log.Println("Docker installed")
124 return nil
125 }
126
127 // Docker not installed, installing Docker
128 cmd = exec.Command("ssh", nodeUser+"@"+node, "yum", "install", "docker", "-y")
129
130 // Set output to standard output and standard error output
131 cmd.Stdout = os.Stdout
132 cmd.Stderr = os.Stderr
133
134 // Execute Command
135 err = cmd.Run()
136 if err != nil {
137 return fmt.Errorf("failed to install Docker on node %s", node)
138 }
139
140 return nil
141}
142
143// Check if the Docker service is started and started
144func checkAndStartDockerService(nodeUser, node string) error {

Callers 1

initClusterFunction · 0.85

Calls 4

OutputMethod · 0.65
RunMethod · 0.65
ErrorfMethod · 0.65
ContainsMethod · 0.45

Tested by

no test coverage detected