;

running docker for windows with rancher on hyper-v

Posted : Monday, 07 August 2017 17:43:39

At Croud we are currently in the process of moving from EC2 hosted monolithic applications to Docker hosted microservices. The reasons for doing this are many and varied but include productivity, support, scalability, availability at so on and so on.

The platform that we are using to manage our containers is an open source product called Rancher, using Rancher delivers a number of benefits such as load balancing, networking, great integration with Docker Cloud and many others. Anyway, I wanted to get our stack running my local machine (a Surface Book running Windows10) but as I’m the only one in the team running Windows (6 Macs, 1 Linux) so if I wanted to do this I was going to have to do it on my own! Looking at the Rancher docs I hit my first bump:

image

Never one to pay attention to docs, I decided to try it out. Downloading and installing the latest version of Docker for Windows was a breeze and after firing up Hyper-V, I could see my brand new Docker Host Virtual Machine had been created:

image

As you can see the new Virtual Machine is called MobyLinuxVM, Moby is a new (ish) open-source initiative to make the Docker container ecosystem flexible, modular and extensible. It also creates an internal virtual network that the Containers can use to communicate.

image

A quick test shows Docker for Windows is up and running:

image

So with Docker for Windows installed, I read the Rancher docs worked out the desired state I wanted which is shown below:

image

At this point I should point out the following…

THIS IS NOT A PRODUCTION SET UP, DO NOT USE THIS SET UP IN PRODUCTION

Anyway the first step was to install the Rancher Server, working through the instructions this is a one line command, I ran it and voila…

image

Further inspection shows the Rancher server running:

image

Browsing http://localhost:8080 returns the Rancher homepage:

image

So the next step is to add a host, this is where it gets a bit meta! What I wanted to do was add the Docker host running the Rancher Server (MobyLinuxVM), as a Rancher Host, to the Rancher Server. Essentially to do this you need to run a command on the Docker host, and this is where I hit a major roadblock. I could not find a way to connect to the MobyLinuxVM – I tried the Hyper-V console, SSH, Putty and could not make a successful connection. I Googled, Binged and trawled forums but got nowhere. Then, nearly on the point of giving up, I was watching this Docker video and came across the following gem:

$> docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i sh

What this essentially does is open a root terminal into a privileged container via the init process (which always runs on the Docker host) thereby enabling you to run commands on the Docker host itself. So pasting the command shown below into the host shell should download the image and then launch a Rancher Agent container (NB the sudo directive is not required in this case):

image

Like so:

image

I had to fiddle about with this to get it to work. The key is to provide a Rancher Server endpoint that is accessible from within the Rancher Agent container. If you are doing this on a desktop computer where your IP is typically unchanging then its fine to just grab your local IP and set this (and port 8080) in the Rancher admin page, however if you’re installing on a Laptop (where your IP often changes) then I would recommend using the internal IP of the Docker Host from the internal network created when installing Docker for Windows – this will typically be 10.0.75.2:8080. Anyway once the host is registered it will show up as follows:

image

One thing to note is that my desired state diagram above does not tell the whole story, as you can see from the screenshot above there are bunch of other services running (all in containers, (obviously)). that deliver DNS, load balancing, scheduling and so on:

image

Once installed its trivial – and I do mean trivial – to launch containers using a few lines of YAML. For example this will install a Wordpress container locally:

version: '2'
services:
wp:
  image: wordpress

Now while this a simple example that could be done much more easily just using docker or docker-compose CLI tools, when you consider the fact that much more complex stacks can be defined, configured, upgraded and scaled as easily then the argument for Rancher becomes more compelling. Layer into that the addition of infrastructure services (DNS, load balancing etc) a Rancher CLI tool and a Rancher REST API then it looks even more attractive. The icing on the cake is the support for orchestration schemes including Kubernetes and Swarm which is what we are currently exploring. Rancher has been designed to be complementary to the Docker platform and rather than get in the way, it simply runs alongside your containers and just makes life easier. Personally I have been blown away with how is it is to use (once setup issues are out of the way) and am really looking forward to exploring the potential even further.

  • (This will not appear on the site)