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.

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

There are two different kind 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: https://msdn.microsoft.com/en-us/virtualization/windowscontainers/management/hyperv_container

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:

docker-windows10-001

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

docker-windows10-003

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…

docker-windows10-004

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

docker-windows10-005

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

docker-windows10-006

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!

docker-windows10-007

You’re done Smile You can now run any Hyper-V container on your Windows 10 computer. Do you like it?

If you have any question about this post or running containers on Windows, feel free to contact me on Twitter @jcorioland

Julien

Comments (20)

      1. John Blanton says:

        When I run the ‘docker run -it -isolation=hyperv nanoserver cmd’ … I get the error message ‘flag provided but not defined: -isolation’ When I use the –isolation switch I get the error messge “unable to find image “nanoserver:latest” locally” Pulling repository docker.io/library/nanoserver” I’m not sure where I’m going wrong.I have all the prereqs installed. Thanks.

        1. Yes, it’s a double dash.
          Did you add the latest tag to the nanoserver image as explained in the post?

  1. Stoneboy says:

    I follow the instruction, but after running in CMD with admin rights:

    “docker run –it –isolation=hyperv nanoserver cmd”

    i get this error: lag provided but not defined: -isolation
    See ‘docker run –help’.

    Howto solve this??

    1. There is a format issue in the command, try with a double dash 😉

  2. Al Maline says:

    Any clues on how to resolve this:

    PS C:\WINDOWS\system32> docker run –isolation=hyperv -it –rm nanoserver cmd

    C:\Program Files\Docker\docker.exe: Error response from daemon: container 739e01e1588a554d2b4aa694327cb24773f8742122af69
    315f9cd03bbf83a876 encountered an error during Start failed in Win32: hcsshim: timeout waiting for notification (0x1f).
    Error response from daemon: Driver Windows filter storage driver failed to remove root filesystem 739e01e1588a554d2b4aa6
    94327cb24773f8742122af69315f9cd03bbf83a876: hcsshim::DestroyLayer failed in Win32: The process cannot access the file be
    cause it is being used by another process. (0x20) id=739e01e1588a554d2b4aa694327cb24773f8742122af69315f9cd03bbf83a876 fl
    avour=1

    1. Hi, I never had this error, sorry. Maybe you can ask on the MSDN forum dedicated to Windows Containers: https://social.msdn.microsoft.com/forums/en-us/home?forum=windowscontainers

  3. Leonardo says:

    I’m suffering with this error when I try to run the command: docker run -it –isolation=hyperv nanoserver:latest cmd

    docker: Error response from daemon: container 1e193368be3c6f6deba8eb4875ee8d588d74a820ed1de82af8e0d7569c692c2e encountered an error during Start failed in Win32: hcsshim: timeout waiting for notification (0x1f).

    what I forgot to do or what I have to do ?

    1. Hi, same answer than above, never got this error. Try the Windows Container forum: https://social.msdn.microsoft.com/forums/en-us/home?forum=windowscontainers

  4. girish says:

    Container feature is not available on the windows 10 Education latest insider build (14390)

  5. Javier Mandiola says:

    How i run the Windows container without admin privilegies?

  6. fishboneuk says:

    Thanks for the post. I’ve read a few different blog posts now and the articles on the MSDN. Still having issues with the Install-ContainerImage call.

    I’ve the features enabled on Windows 10 Enterprise (anniversary edition) and no matter what actions I take I’m always presented with the following:

    Install-ContainerOSImage : The term ‘Install-ContainerOSImage’ is not recognized as the name of a cmdlet, function, script file, or operable program.

    A few posts have suggested that the Container feature is not enabled; however it is most definitely showing up as enabled in the Windows feature list. It does appear that the Get-Command -Module Containers only shows the following:

    CommandType Name Version Source
    ———– —- ——- ——
    Cmdlet Get-ContainerNetwork 1.0.0.0 Containers
    Cmdlet New-ContainerNetwork 1.0.0.0 Containers
    Cmdlet Remove-ContainerNetwork 1.0.0.0 Containers

    Which for sure does not include the Install-ContainerOSImage.

    Any thoughts or pointers in the right direction?

    Cheers

    1. Hi, for those kinds of questions prefer the Windows Container dedicated forum please: https://social.msdn.microsoft.com/forums/en-us/home?forum=windowscontainers

  7. chirag says:

    when i ran docker run -it –isolation=hyperv nanoserver cmd i got following error did anyone got these error
    docker: Error response from daemon: container bb0bca5ac853ff2f21b3666f96051f5d78b791d3b85cf40fb17454acfcb46608 encountered an error during Start failed in Win32: winapi error #3489661596 (0xd000029c).

    1. Hi, for those kinds of questions, prefer the Windows Container dedicated forum please: https://social.msdn.microsoft.com/forums/en-us/home?forum=windowscontainers

  8. msitekkie says:

    The information given in the more recent article “Windows Containers on Windows 10” on MSDN here:
    https://msdn.microsoft.com/en-gb/virtualization/windowscontainers/quick_start/quick_start_windows_10
    Is different to the above. I appreciate turning the Windows features on can be done either via the GUI or command line, but it’s the steps following this where it becomes more murky. Please can you clarify.

  9. Kishor Maharjan says:

    Getting following error when I run:-

    PS C:\WINDOWS\system32> docker run -it microsoft/nanoserver powershell

    C:\Program Files\Docker\docker.exe: Error response from daemon: container 13f315185532906e9a98b521a1e9010eb3ec0db97841917d1b15e65ba8b3ec5b encountered an error during CreateContainer: failure
    in a Windows system call: No hypervisor is present on this system. (0xc0351000).

    1. Hi, have you installed hyper-v and enabled the Windows containers feature on your machine?

Skip to main content