0

I have installed minikube on my laptop, I see that minikube uses docker daemon running within cluster.

Is it possible to run minikube to use the host machine docker daemon?

I tried using

export DOCKER_HOST="tcp://localhost:2376" ran, minikube start

and, minikube start --docker-env=DOCKER_HOST="tcp://localhost:2376"

Both did not work.

Sunil Gajula
  • 1,117
  • 2
  • 14
  • 30

3 Answers3

2

Is it possible to run minikube to use the host machine docker daemon?

No. Minikube runs in a VM, and can't connect to the host's /var/run/docker.sock file. (The setup you show requires a non-default host Docker configuration with significant risk of just outright getting the host rooted, and from the VM's point of view, localhost is the VM.)

You can do the opposite, though, set your local Docker daemon to talk to minikube's Docker daemon

eval $(minikube docker-env)

(Also remember that Kubernetes is designed for multi-host deployments based around immutable images. If you're trying to do live development inside a Kubernetes pod, it is rather complicated and translates poorly to production environments. Use plain Docker, or better still, install a development environment directly on your host. If you're just trying to test out deployment wiring, minikube, or the Kubernetes included in Docker Desktop, or other tools like kind work just fine.)

David Maze
  • 130,717
  • 29
  • 175
  • 215
  • There was another discussion on with some more information. https://stackoverflow.com/questions/42564058/how-to-use-local-docker-images-with-minikube – Manuel Aug 08 '19 at 23:15
  • Minikube can run as a set of docker containers. However, the docker driver seems to ignore DOCKER_HOST for alternative installs. (ie. docker-rootless) – Merijn Vogel Jun 09 '20 at 19:45
1

@David Maze, it's not completely true what you wrote in your answer:

No. Minikube runs in a VM, and can't connect to the host's /var/run/docker.sock file.

Let's say it can be true only in particular case, so the following question:

Is it possible to run minikube to use the host machine docker daemon?

I would answer: Yes, it is. However typical Minikube instance runs on a separate VM, it is still possible to run it directly on the host. More on that you can read in minikube installation guide in official Kubernetes documentation:

Note: Minikube also supports a --vm-driver=none option that runs the Kubernetes components on the host and not in a VM. Using this driver requires Docker and a Linux environment but not a hypervisor. It is recommended to use the apt installation of docker from Docker, when using the none driver. The snap installation of docker does not work with minikube.

@Sunil Gajula, adding following flag:

--vm-driver=none

when running your Minikube instance should actually resolve your problem as it is not set by default to none and it seems the missing element in your attempts to run Minikube on your local machine. So by default it runs in a VM, using one of the available hypervisors ( if you don't specify above mentioned flag).

mario
  • 9,858
  • 1
  • 26
  • 42
  • @mariom `--vm-driver=none` option is supported only on Linux environment. This does not work on Mac and Windows. – Sunil Gajula Aug 19 '19 at 13:08
  • Tried `--vm-driver=none` on `mac`, this option does not work, – Sunil Gajula Aug 19 '19 at 13:10
  • Yes, you're right. On Mac there is no such option. You didn't mention in your question you're using Mac so I assumed you run it on Linux which is default option. – mario Aug 19 '19 at 13:22
0

I got this working on my mac OS. And I use fish:

##install docker-cli
#brew install docker

#brew install minikube hyperkit

## run minikube without kubernetes enabled
#minikube start --memory 6144 --cpus 4 --docker-opt=bip=172.17.42.1/16 --no-kubernetes
# minikube -p minikube docker-env | source   (put the result into config and source it)for bash/zsh: minikube docker-env

And if you want to run minikube k8s cluster: you can: # minikube start --addons=registry --cni=calico --driver=hyperkit --cpus=8 --memory=8g (or some simple command)

You may need to install docker-machine-driver-hyperkit with install command.

With everything ok, you can use docker-cli to interact docer daemon in minikube.

Dharman
  • 30,962
  • 25
  • 85
  • 135
4t8dds
  • 565
  • 7
  • 19
  • Well, you can not operate images directly with docker-cli. You will have to manage that with minikube image. – 4t8dds Mar 12 '22 at 03:23