Home - About me - Browse by categories

Create and run Hyper-V containers using Docker on Windows 10 desktop

As you probably know the Windows Insider program allows to get preview Windows 10 builds to test the new features that are coming in the next major update of Windows. Since a few weeks, a new feature named Container has been included in Windows 10 preview builds. This feature brings Hyper-V containers on the desktop, natively.

Note: The following will work only on Windows 10 Professional and Enterprise.

There are two different kinds of containers on Windows : Windows Container and Hyper-V Container. They work in the same way, instead of that Hyper-V containers are more isolated than Windows Container because they are running in a very lightweight virtual machine that provides kernel isolation and not just process isolation.

For more information about Hyper-V containers, check the official documentation on MSDN

You want to try it? It’s pretty simple! First, you need to enroll your machine in the Windows Insider program (see link above) and get the latest build from the insider fast ring.

Once done, just open the Turn Windows features on or off, then select Containers and Hyper-V in the list:

Turn On Off Features

Click OK to install the two components and restart your computer when the installation has completed.

Now, open a PowerShell console in administrator mode. The first thing to do is to change the execution policy to unrestricted using the following command:

Set-ExecutionPolicy Unrestricted

Then you can install the ContainerImage package provider:

Install-PackageProvider ContainerImage -Force

PowerShell

This package provider will allow you to pull the base operating system image to run Hyper-V containers. In this case, as you are going to run Hyper-V container you need to use the NanoServer base container image. To pull this image, you have to execute the following command:

Install-ContainerImage NanoServer

Depending on your Internet connection, this step can take a while…

Once the base container image is downloaded you can install Docker on your machine to be able to run and manage containers. To do that, you can download a PS script from http://aka.ms/tp5/update-containerhost and save it on your computer. Just run this script that will install all the stuff you need: the Docker client, the Docker deamon, all the configuration, environment variables…

PowerShell

You can now use the Docker commands to work with Hyper-V containers! For example getting the list of available images on your computer:

PowerShell

To be able to use this image without specifying its tag you can tag it as the latest image using the docker tag command:

PowerShell

Now you can switch to a CMD window, with administrator rights and create a new Hyper-V container use the following command:

docker run –it --isolation=hyperv nanoserver cmd

After a few seconds you will be running in an Hyper-V container!

PowerShell

You’re done! You can now run any Hyper-V container on your Windows 10 computer.

Do you like it?


Any question about this post? Feel free to drop a comment below or contact me on Twitter @jcorioland