Skip to content

Commit 87536a1

Browse files
Saurabh DeulkarbhavyaBeliever
authored andcommitted
docker-env: change the username to root during --ssh-host
1 parent 73adedf commit 87536a1

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

cmd/minikube/cmd/docker-env.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
384384
sshAgentPID: co.Config.SSHAgentPID,
385385
}
386386

387+
if sshHost == true {
388+
ec.username = "root"
389+
sshAdd = true
390+
}
391+
387392
dockerPath, err := exec.LookPath("docker")
388393
if err != nil {
389394
klog.Warningf("Unable to find docker in path - skipping connectivity check: %v", err)
@@ -425,7 +430,7 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
425430
}
426431

427432
// TODO: refactor to work with docker, temp fix to resolve regression
428-
if cr == constants.Containerd {
433+
if cr == constants.Containerd || cr == constants.Docker {
429434
// eventually, run something similar to ssh --append-known
430435
appendKnownHelper(nodeName, true)
431436
}

cmd/minikube/cmd/start.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,27 @@ func startNerdctld(options *run.CommandOptions) {
20952095

20962096
// set up environment variable on remote machine. docker client uses 'non-login & non-interactive shell' therefore the only way is to modify .bashrc file of user 'docker'
20972097
// insert this at 4th line
2098-
envSetupCommand := exec.Command("/bin/bash", "-c", "sed -i '4i export DOCKER_HOST=unix:///var/run/nerdctl.sock' .bashrc")
2099-
if rest, err := runner.RunCmd(envSetupCommand); err != nil {
2100-
exit.Error(reason.StartNerdctld, fmt.Sprintf("Failed to set up DOCKER_HOST: %s", rest.Output()), err)
2098+
checkDockerHostCmd := exec.Command("/bin/bash", "-c", "echo $DOCKER_HOST")
2099+
dockerHostResult, err := runner.RunCmd(checkDockerHostCmd)
2100+
if err != nil {
2101+
exit.Error(reason.StartNerdctld, fmt.Sprintf("Failed to check DOCKER_HOST: %s", dockerHostResult.Output()), err)
2102+
}
2103+
if !strings.Contains(dockerHostResult.Output(), "unix:///var/run/nerdctl.sock") {
2104+
envSetupCommand := exec.Command("/bin/bash", "-c", "sed -i '4i export DOCKER_HOST=unix:///var/run/nerdctl.sock' .bashrc")
2105+
if rest, err := runner.RunCmd(envSetupCommand); err != nil {
2106+
exit.Error(reason.StartNerdctld, fmt.Sprintf("Failed to set up DOCKER_HOST: %s in /home/docker/.bashrc", rest.Output()), err)
2107+
}
2108+
}
2109+
2110+
checkDockerHostCmd = exec.Command("sudo", "-i", "bash", "-c", "echo $DOCKER_HOST")
2111+
rootDockerHostResult, err := runner.RunCmd(checkDockerHostCmd)
2112+
if err != nil {
2113+
exit.Error(reason.StartNerdctld, fmt.Sprintf("Failed to check root DOCKER_HOST: %s", rootDockerHostResult.Output()), err)
2114+
}
2115+
if !strings.Contains(dockerHostResult.Output(), "unix:///var/run/nerdctl.sock") {
2116+
envSetupCommand := exec.Command("/bin/bash", "-c", "sudo sed -i '4i export DOCKER_HOST=unix:///var/run/nerdctl.sock' /root/.bashrc")
2117+
if rest, err := runner.RunCmd(envSetupCommand); err != nil {
2118+
exit.Error(reason.StartNerdctld, fmt.Sprintf("Failed to set up DOCKER_HOST: %s in /root/.bashrc", rest.Output()), err)
2119+
}
21012120
}
21022121
}

0 commit comments

Comments
 (0)