Skip to content

Commit b9345da

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

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

cmd/minikube/cmd/docker-env.go

+33-3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,24 @@ 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(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(r command.Runner) {
251+
sysinit.New(r).Start("podman.socket")
252+
}
253+
236254
func waitForAPIServerProcess(cr command.Runner, start time.Time, timeout time.Duration) error {
237255
klog.Infof("waiting for apiserver process to appear ...")
238256
err := apiWait.PollUntilContextTimeout(context.Background(), time.Millisecond*500, timeout, true, func(_ context.Context) (bool, error) {
@@ -312,14 +330,26 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
312330
exit.Message(reason.Usage, err.Error())
313331
}
314332

333+
forceSSH := false
334+
315335
// for the sake of docker-env command, start nerdctl and nerdctld
316336
if cr == constants.Containerd {
317337
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")
318338

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

349+
if forceSSH {
321350
// docker-env on containerd depends on nerdctld (https://github.com/afbjorklund/nerdctld) as "docker" daeomn
322351
// and nerdctld daemon must be used with ssh connection (it is set in kicbase image's Dockerfile)
352+
// the podman service must be used with ssh connection (it does not support tcp connection)
323353
// so directly set --ssh-host --ssh-add to true, even user didn't specify them
324354
sshAdd = true
325355
sshHost = true
@@ -342,6 +372,9 @@ docker-cli install instructions: https://minikube.sigs.k8s.io/docs/tutorials/doc
342372
if cr == constants.Docker {
343373
ensureDockerd(cname, r)
344374
}
375+
if cr == constants.CRIO {
376+
ensurePodman(cname, r)
377+
}
345378

346379
d := co.CP.Host.Driver
347380
port := constants.DockerDaemonPort
@@ -672,9 +705,6 @@ func tryDockerConnectivity(bin string, ec DockerEnvConfig) ([]byte, error) {
672705
}
673706

674707
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-
}
678708
// we only support containerd-env on the Docker driver
679709
if containerRuntime == constants.Containerd && driverName != driver.Docker {
680710
return fmt.Errorf("the docker-env command only supports the containerd runtime with the docker driver")

0 commit comments

Comments
 (0)