Sam Debruyn

Cloud Data Solution Architect

Specialized in Microsoft Azure, Fabric & modern data stack. Microsoft Data Platform MVP. dbt Community Award. Public speaker & meetup organizer. OSS contributor.

Sam Debruyn

Run Docker on Hyper-V with Docker Machine

3 minutes

Docker is awesome, right? And thanks to boot2docker Windows users were no longer left out of the fun.

Still, setting everything up could be a PITA and you had to install Oracle VirtualBox to use it as Docker containers were actually run inside of a VM (which was the purpose of boot2docker). If you use Hyper-V regularly, you’ll notice that you can’t have it both ways. Scott Hanselman figured out a way to make switching between the two a little bit less painful, but you still had to reboot your machine if you wanted to use VirtualBox.

Time to fix that! You can now use Hyper-V to run the boot2docker VM and connect to Docker on Windows. I guess that this has been possible since boot2docker was released, but it wasn’t that straightforward to set up at the time. Enter Docker Machine .

TL;DR: Docker Machine is a cross platform utility to help you set up, manage and connect to Docker. It automagically (well, most of the time) picks the best way to set up Docker in your environment. That’s the boot2docker VM on Windows with either VirtualBox either Hyper-V, plain old Docker on Linux etc.

Docker still recommends using VirtualBox on Windows, but Docker Machine supports tons of other drivers : AWS, Digital Ocean, Google Compute, Azure, Rackspace, Hyper-V…

So how do you install Docker Machine on Windows with Hyper-V? Here we go.

Setting up Hyper-V and network connections

Make sure the Hyper-V role is installed on your computer and the Hyper-V Manager works fine. I still had to fix a small issue on Windows 10 .

Next, create a Virtual Network Switch. Pick internal as type.

Then go to your Network Connections, open the properties of your active internet connection and share the connection with the newly created virtual network switch. This will make sure that the IP of the boot2docker VM never changes and it still has internet access.

Download and install Docker Machine

You don’t need Docker Toolbox if you’re not going to use Oracle VirtualBox. Just download the latest version of Docker Machine from GitHub , rename it to docker-machine.exe and put it in your PATH. That’s all there is to it.

Create a new Docker Machine with the Hyper-V driver

Now open an administrative command prompt (you need to be an administrator to create new virtual machines) and execute the following command to create a new Docker Machine named boot2docker. Make sure to replace My Internal Switch with the name of the internal switch you created before. You can add --hyper-v-memory xxxx before the name of the machine to change the default amount of memory (it’s dynamic) from 1024 to something else.

1docker-machine create --driver hyperv --hyperv-virtual-switch "My Internal Switch" boot2docker

If all went well, you should get a message saying you still need to set the environment variables to connect to the machine. Running the following command will give you a few more commands to run which set the required variables.

1docker-machine env --shell cmd boot2docker

Connect to your boot2docker instance

You can now connect to your newly created boot2docker instance with the following command as it should already be running:

1docker-machine ssh boot2docker

A few more helpful commands:

1docker-machine --help
2docker-machine stop boot2docker
3docker-machine start boot2docker
4docker-machine restart boot2docker
5docker-machine kill boot2docker

If you need more fine-grained control, you can still use the Hyper-V Manager to adjust more settings.

You might also like

If you liked this article, follow me on LinkedIn or other social media to stay up-to-date with my latest posts. You might also like the following 2 posts about related topics:

How to fix common Hyper-V errors on Windows 10

1 minutes

This short post is more of a note to myself for when I run into the same problem. I just wasted an hour on it so I guess that justifies it. So, what happened? I wanted to check out the new Docker Machine with Hyper-V support, but the Hyper-V Manager told me it could not connect to my local computer.

Docker image for Hugo builds (with Wercker)

2 minutes

This blog is built with Hugo , which allows me to use some great CI tools like Wercker . The first part of writing a wercker.yml is picking a build container. A build container on Wercker is the environment in which your build or deploy steps run. Wercker used to build its own containers for that, but they’ve moved away from that approach to Docker containers.