3

When I run my docker container using Docker Desktop for Windows I am able to connect to it using

docker run -p 5051:5000 my_app

http://0.0.0.0:5051

However when I open another terminal and do this

minikube docker-env | Invoke-Expression

and build and run the same container using the same run command as above

I cannot connect to the running instance.

Should I be running and testing the containers using Docker Desktop, then using minikube to store the images only (for Kubernetes)? Or can you run them and test them as well through minikube?

erotavlas
  • 4,274
  • 4
  • 45
  • 104
  • Do you have any specific reason to use **Docker Desktop** and **Minikube** together on a single machine ? – mario Jan 30 '20 at 16:58
  • @mario no, I didn't know minikube had a docker daemon until recently which is why I have both – erotavlas Jan 30 '20 at 17:36

2 Answers2

5

That's because on your second attempt, the container is not running on the host but on the minikube VM. You'll be able to access it using the minikube VM IP.
To get the minikube ip you can run minikube ip

Why ?

Invoking minikube docker-env sets all the docker env variable on your host to match the minikube environment. This means that when you run a container after that, it is run with the docker daemon on the minikube VM.

Marc ABOUCHACRA
  • 3,155
  • 12
  • 19
1

I asked you if there are any specific reasons to use Docker Desktop and Minikube together on a single machine as these are two competitive solutions which basically enable you to perform similar tasks and achieve same goals.

This article nicely explains differences between these two tools.

Docker-for-windows uses Type-1 hypervisor, such as Hyper-V, which are better compared to Type-2 hypervisors, such as VirtualBox, while Minikube supports both hypervisors. Unfortunately, there are a couple of limitations in which technology you are using, since you cannot have Type-1 or Type-2 hypervisors running at the same time on your machine

If you use Docker Desktop and Minikube at the same time I assume you're using Type-1 hypervisor, such as mentioned Hyper-V, but keep in mind that even if they use the same hypervisor, both tools create their own instances of virtual machine. Basically you are not supposed to use those two tools together expecting that they will work as a kind of hybrid that lets you manage single container environment.

First check what hypervisor you are using exactly. If you're using Hyper-V, simple Get-VM command in Powershell (more details in this article) should tell you what you currently have.

@mario no, I didn't know minikube had a docker daemon until recently which is why I have both

Yes, Minikube has built in docker environment (in fact it sets everything up, but yes, it also sets up container runtime) so basically you don't need to install docker additionally, and as @Marc ABOUCHACRA already suggested in his answer, Minikube runs the whole environment (single node k8s cluster with docker runtime) on a separate VM. Linux version has an option --vm-driver=none which allows you to use your host container runtime and set-up k8s components on it, but this is not the case with Windows version - here you can only use one of two currently supported hypervisors: Hyper-V or VirtualBox (ref).

I wouldn't say that Docker Destkop runs everything on your host. It also uses Type-1 hypervisor to run the container runtime environment. Please check the Get-VM command on your computer and it should be clear what VMs you have and created by which tool.

mario
  • 9,858
  • 1
  • 26
  • 42