Skip to content

Commit 3f59246

Browse files
committed
Add support for using podman with docker-env
1 parent 970161c commit 3f59246

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

cmd/minikube/cmd/docker-env.go

+36-3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,27 @@ func mustRestartDockerd(name string, runner command.Runner) {
233233
}
234234
}
235235

236+
// ensurePodman ensures podman inside minikube is running before a docker-env command
237+
func ensurePodman(name string, r command.Runner) {
238+
if ok := isPodmanActive(r); ok {
239+
return
240+
}
241+
startPodman(name, r)
242+
}
243+
244+
// isPodmanActive checks if Podman is active
245+
func isPodmanActive(r command.Runner) bool {
246+
return sysinit.New(r).Active("podman.socket")
247+
}
248+
249+
// startPodman will attempt to start podman
250+
func startPodman(name string, r command.Runner) {
251+
if err := sysinit.New(r).Start("podman.socket"); err != nil {
252+
klog.Warningf("Couldn't start podman inside minikube within '%v' because: %v", name, err)
253+
return
254+
}
255+
}
256+
236257
func waitForAPIServerProcess(cr command.Runner, start time.Time, timeout time.Duration) error {
237258
klog.Infof("waiting for apiserver process to appear ...")
238259
err := apiWait.PollUntilContextTimeout(context.Background(), time.Millisecond*500, timeout, true, func(_ context.Context) (bool, error) {
@@ -312,14 +333,26 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
312333
exit.Message(reason.Usage, err.Error())
313334
}
314335

336+
forceSSH := false
337+
315338
// for the sake of docker-env command, start nerdctl and nerdctld
316339
if cr == constants.Containerd {
317340
out.WarningT("Using the docker-env command with the containerd runtime is a highly experimental feature, please provide feedback or contribute to make it better")
318341

319342
startNerdctld()
343+
forceSSH = true
344+
}
345+
if cr == constants.CRIO {
346+
if _, err := co.CP.Runner.RunCmd(exec.Command("sudo", "ln", "-sf", "/run/podman/podman.sock", "/var/run/docker.sock")); err != nil {
347+
exit.Message(reason.SSHAgentStart, err.Error())
348+
}
349+
forceSSH = true
350+
}
320351

352+
if forceSSH {
321353
// docker-env on containerd depends on nerdctld (https://github.com/afbjorklund/nerdctld) as "docker" daeomn
322354
// and nerdctld daemon must be used with ssh connection (it is set in kicbase image's Dockerfile)
355+
// the podman service must be used with ssh connection (it does not support tcp connection)
323356
// so directly set --ssh-host --ssh-add to true, even user didn't specify them
324357
sshAdd = true
325358
sshHost = true
@@ -342,6 +375,9 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
342375
if cr == constants.Docker {
343376
ensureDockerd(cname, r)
344377
}
378+
if cr == constants.CRIO {
379+
ensurePodman(cname, r)
380+
}
345381

346382
d := co.CP.Host.Driver
347383
port := constants.DockerDaemonPort
@@ -672,9 +708,6 @@ func tryDockerConnectivity(bin string, ec DockerEnvConfig) ([]byte, error) {
672708
}
673709

674710
func dockerEnvSupported(containerRuntime, driverName string) error {
675-
if containerRuntime != constants.Docker && containerRuntime != constants.Containerd {
676-
return fmt.Errorf("the docker-env command only supports the docker and containerd runtimes")
677-
}
678711
// we only support containerd-env on the Docker driver
679712
if containerRuntime == constants.Containerd && driverName != driver.Docker {
680713
return fmt.Errorf("the docker-env command only supports the containerd runtime with the docker driver")

0 commit comments

Comments
 (0)