Unable to connect to running docker containers (minikube docker daemon) - docker

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?

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.

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.

Related

Detect Docker for Windows vs Docker Native inside of WSL2 VM

So I have a use case where I need to detect inside of a WSL2 VM whether the Docker setup is Docker for Windows w/ WSL integration vs Docker just running inside of the WSL VM (say installed directly via apt or dnf). The networking situation between these two use cases is different because with Docker for Windows WSL integration you cannot reach containers by their IP from the WSL VM. This poses some problems for some dev-tooling that we have and wasn't previously an issue with devs running on Linux-native machines but we've recently run into it now that some devs are using Windows machines with WSL and Docker for Windows.
Any thoughts on how I can do this? Look for specific env vars, mount points etc?
Looks like I can just stat /mnt/wsl/docker-desktop and see if that exists.

Why minikube runs as a container itself?

While playing around with Docker and orchestration (kubernetes) I had to install and use minikube to create a simple sandbox environment. At the beginning I thought that minikube installs some kind of VM and run the "minified" kubernetes environment inside the same, however, after the installation listing my local Docker running containers I found minikube running as a container!!
Why minikube itself run as a Docker container? and how can it runs other containers?
Experimental Docker support looks to have been added in minikube 1.7.0, and started becoming the default runtime in minikube 1.9.0. As I'm writing this, current is 1.15.1.
The minikube documentation on the "docker" driver notes, particularly on a native-Linux host, there is not an intermediate virtual machine: if you can run Kubernetes in a container, it can use the entire host system's resources without special configuration or partitioning. The previous minikube-on-VirtualBox installation required preallocating memory and disk to the VM, and it was easy to get those settings wrong. Even on non-Linux hosts, if you're running Docker Desktop, sharing its hidden Linux VM can improve resource utilization, and you don't need to decide to allocate exactly 2 GB RAM to Docker Desktop and exactly 4 GB to the minikube VM.
For a long time it's been possible, but discouraged, to run a separate Docker daemon inside a Docker container; similarly, it's possible, but usually discouraged, to run a multi-process init system in a container. If you do both of these things then you can have the core Kubernetes components (etcd, apiserver, kubelet, ...) inside a single container pretending to be a Kubernetes node. It also helps here that Kubernetes already knows how to pull Docker images, which minimizes some of the confusing issues with running Docker in Docker.

How to use Molecule inside a VM to test an Ansible role that installs Docker

I have an Ansible role that among other things installs Docker and starts the docker daemon in a CentOS environment. I would like to use Molecule to test it, but as my workstation is a Windows PC I have to run Molecule from a VirtualBox VM. At least theoretically my options are:
Use Molecule's Vagrant driver and run a VM inside my VM
Use Molecule's Docker driver and have a docker container which starts the docker daemon.
As far as I can tell the first option is not really possible with VirtualBox; is there a way to achieve the second one? I searched around, but all the posts I found concerned running Molecule itself from within a container rather than the setup I described.
If I try to use a default Molecule scenario systemctl fails to start the docker daemon.

Docker inside Windows VirtualBox

here's the thing: I tried to install docker inside a windows which runs inside virtualbox, and off course I failed due it's not possible (now I know this is due Hyper-V not used by virtualbox and required by docker).
Since for me migrating to VMWare ain't an option, I dig a little bit and found out that there's no problem on running docker inside a linux distro (which runs inside a vbox), so here's the question.
Is it possible to run 2 different virtual machines with virtualbox, one with linux (running docker inside it), and the other one with windows as my development environment, both at the same time and to develop on windows and then deploy and run tests on docker? If this is possible, how? Any links or keywords for me to search for would be appreciated.
Sure! You need to do following steps:
You should set your VMs network so then can see easily each other https://superuser.com/questions/119732/how-to-do-networking-between-virtual-machines-in-virtualbox
You should expose docker daemon on TCP socket on VM with linux https://success.docker.com/article/how-do-i-enable-the-remote-api-for-dockerd
On VM with windows you need to create some override for docker client so he will connect to remote daemon on linux machine https://gist.github.com/kekru/4e6d49b4290a4eebc7b597c07eaf61f2#create-bat-file-for-windows
Please keep in mind when you expose some service under ports you won't access that on VM with windows on localhost - instead of that you need to type: :

Using commands in bluemix user interface

I need to use docker container in bluemix but my laptop does not support docker so I can't use the commands to run docker in bluemix using the CLI plug-ins.
Is there any other way to do this?
Why can't you run it on your laptop? Docker can run in some flavor on most operating systems (albeit within a VM on some).
You have a number of options though:
Run it inside a linux virtual machine locally
Run it inside a cloud linux virtual machine
Run it inside a cloud container - Yes, you can actually run Docker inside a Docker container.
Install a linux OS as a dual boot option on your laptop and run Docker there.
Edit: formatting
which OS does your notebook run?
Docker supports Linux, OSX and Windows as well, and you could choose to use cf container plugin (cf ic), docker or also ice client.
Here you could find Bluemix documentation related to container

Resources