Sometimes you just want to test something inside a virtual machine, however when you want to run something like Docker inside a virtual machine you will experience some issues when starting Docker as shown here below.

Or a small red Moby whale in the Windows taskbar.

The solution to solve this issue is to enable nested virtualization on the host machine (the physical machine).
When enabled it should be possible to start virtual machines inside virtual machines 🙂

Virtual Machines inside Virtual Machines?

Yup you read it correct, when running Docker inside a virtual machine it will start another (little helper) virtual machine.
This is because Docker on Windows will start by default with Linux support enabled.
So it needs a small Linux virtual machine to run the Linux containers, as shown here below in the Hyper-V Manager console.

When opening the Hyper-V Manager you can see there is a Virtual Machine named MobyLinuxVM. This is the little helper VM to be able to run Linux containers “on top” of Windows.

Even when Docker for Windows is switched over to Windows Containers it still uses Hyper-V in the background to spin up a virtual machine in order to run the Windows based container.

Pre-requirements

Besides the most logical things like a supported Windows version (Windows 10 Pro or Enterprise) and have the Hyper-V role enabled.

It’s also required to enable the VT-x (Intel) or AMD-V (AMD) feature in the BIOS or UEFI Firmware of your physical machine.

How to do this depends on your computer and could be different from vendor to vendor. If you can’t find any options in the BIOS or UEFI, try Googling on the model name and “virtualization option” it should give you an indication where to enable the correct options in the BIOS or UEFI.

Enable “ExposeVirtualizationExtensions” in Hyper-V

Enabling the virtualization option is very simple, however the command below needs to be run in a Administrative PowerShell session (Windows Powershell –> right click –> Run as Administrator). But before executing this command the virtual machine needs to be powered-off, when it is turned off your good to go and execute the command below.

The PowerShell script can be found over here on GitHub, or just copy it below.
Make sure that you change the Virtual Machine name (in this example it’s “Windows 10 dev environment” to the one matches your name.

Set-VMProcessor -VMName "Windows 10 dev environment" -ExposeVirtualizationExtensions $true

Once you see a new clear line, the virtualization extension are enabled for this virtual machine and you can start the virtual machine.

Running “nested” containers

Now login to Windows and open a normal Windows Powershell window.
To start the Hello World container, execute the command below

Note: in this example Docker will start a Linux based container that displays some text output, however the command is the same for both Linux and Windows Containers.

docker run hello-world


Happy Dockering!!


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.