Docker inside Windows VirtualBox - docker

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: :

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.

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

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.

Why does Docker for Windows make you pick either Windows or Linux containers?

When using Docker for Windows, you must choose to either use Windows or Linux containers, but you can't use both at the same time. What is the technical reason(s) for this? It's a little counter-intuitive, since each container has its own isolated operating system.
Linux containers on Docker for Windows are not handled by windows itself, but they are using Hyper-V Linux VM - MobyLinuxVM. Hence the necessity to switch between Linux and Windows.
However starting from Windows 1709 and Docker in edge version you can try out linux containers on windows - see: https://blog.docker.com/2017/09/docker-windows-server-1709/
Update
As #v.karbovnichy brought up, technically on Docker for Windows you "can" run linux and windows containers simultanously - you can use docker-machine command to create additional linux-based virtual machine that will run your linux containers. Then, you can connect them into one swarm and, with a dose of good will, you will run linux and windows containers simultaneously on same machine.
docker client command itself can connect to both linux or windows docker-server and "manage" both of them - check docker login - it's widely used in server configurations.
However as stated above, true running linux and windows containers next to each other is in preview state.
Docker ecosystem on your Windows machine contains several components.
One is Docker command line: the docker command that you use for everything-management. The second one is Docker daemon - A self-sufficient runtime for containers, the core.
Docker daemons for Linux Containers and Windows Containers are different, but they listen for connections from the docker client on the same pipe. So one needs to be stopped for other to be started. This is the technical reason that you asked for.
However, you can observe that containers started for ex. in MobyLinuxVM is still running and available for connections when you switch to Windows containers. The only thing here is that you cannot manage them because the Docker daemon for Windows does not know how to manage Linux containers in MobyLinuxVM.
UPDATE: As described in this post,
Docker for Windows 18.02 now supports Linux and Windows containers running side-by-side via LCOW, using a single Docker daemon.
So actually now you can use one docker daemon to manage both worlds, it's just about using the new --platform flag in docker pull.

Docker: Why use Linux containers on Windows?

I am using Win 10 Pro N (Version 1709) as a development machine and Windows Server 2016 Standard (Version 1607) as production server.
I am currently developing an ASP.NET Core 2 application with MongoDb as database.
A couple days ago I first stumbled over the idea, to run MongoDb as a Docker image.
I don't have any experience with Docker so far, but I managed to switch from Linux containers (default) to Windows containers on Windows machines.
Was this a good decision? Or is there any reason why I should use Linux containers instead of Windows containers in my scenario?
What e.g. if I should decide to deploy my application to a Linux server some time? In this case, would it wiser to start with Linux containers right from the beginning?
Docker is not about virtualization but more about isolation.
A windows container will run on a windows host
A linux container will run on a linux host
Then some people wanted to run linux container on windows
First you needed to create a linux vm on windows to run the container
Now you can use LinuxKit to run the container but it's still a light VM
Then some people wanted to run windows container on linux
First you needed to create a windows vm on linux to run the container
Now you can use nothing more as of today
So the best bet is to start with a container aimed at your production servers
If you want to deploy to linux I would advise using linux containers since you then test a more similar setup and are more likely to find issues that will also show in your final deployment.
Other than that linux container technology is more mature and better supported than windows containers.

windows docker on vmwarevsphere

we use VMWare vSphere for VMs in our company.
To automatically create docker hosts we use one simple command:
docker-machine --driver vmwarevsphere .... vm params(cpu,memory,network,name, etc)
It automatically creates new VM machine in our VM cluster, installs docker and then we add it to swarm or create new.
Right now I need to create windows docker hosts to run windows containers.
Docker-machine installs boot2docker.iso after creating VM.
But instead I need VM with microsoft servercore or nano.
How do I do it?
Thanks a lot.
Anton
On a Windows machine with Docker for Windows installed you could run the following command to pull the official images for server or nanoserver
docker pull microsoft/nanoserver
or
docker pull microsoft/windowsservercore
I'm not exactly sure how you're automating this - are you using a dockerfile or docker compose?
Are you talking about setting up the Windows host that runs Docker engine? If so, Docker for Windows CE is meant to be desktop software so not recommended for server side workload. Also, Windows EE Server requires Windows Server 2016 or later. If you would really like to use Windows server core mode, Windows Server 1709 offers that. Still, it quite bit new, so you should not set high expectations just yet.
As per the instruction to install the engine, MS has this.
https://learn.microsoft.com/en-us/virtualization/windowscontainers/quick-start/quick-start-windows-server
Or, equivalent one from Docker here.
https://docs.docker.com/engine/installation/windows/docker-ee/
you are talking about hosting a windows container on VMware vSphere? I don't think this is possible right now, may be in the future. I have no documentation or link to verify my answer but in our company we have a similar situation and use vSphere for VMs and Linux container and Hyper-V in parallel for VMs and windows container.

Resources