Run Linux containers on Windows

Key Value
Summary Run Ubuntu containers with Hyper-V isolation on Windows 10 and Windows Server.
Categories containers
Difficulty 5
Author Mathieu Trudel-Lapierre mathieu.trudel-lapierre@canonical.com

Overview

Duration: 1:00

It is now possible to run Docker containers on Windows 10 and Windows Server, leveraging Ubuntu as a hosting base.

Imagine running your own Linux applications on Windows, using a Linux distribution you are comfortable with: Ubuntu!

It is now possible to do so using the power of Docker technology and Hyper-V virtualization on Windows.

screenshot

Originally authored by Mathieu Trudel-Lapierre.

Requirements

Duration: 5:00

You will need a 64-bit x86 PC with 8GiB of RAM running Windows 10 or Windows Server, updated to include the Windows 10 Fall Creator update, released October 2017.

You will also need a recent installation of Docker.

Finally, you will need to make sure you have installed a program for decompressing the Ubuntu host container image, e.g. 7-Zip or XZ Utils

Install Docker for Windows

Duration: 2:00

Download Docker for Windows from Docker Store.

Once downloaded, proceed with the installation steps, and either logout or reboot of your system as indicated by the installer.

screenshot

After reboot, Docker will be started. Docker requires that the Hyper-V feature is enabled, so if necessary will ask you to enable it and restart. Click OK for Docker to enable Hyper-V and restart your system.

screenshot

Download the Ubuntu container image

Duration: 4:00

Download the latest Ubuntu container image for Windows from the Canonical Partner Images website

Once downloaded, extract the image, using e.g. 7-Zip, or XZ Utils:

C:\Users\mathi\> .\xz.exe -d xenial-container-hyper-v.vhdx.xz

Prepare the container environment

Duration: 2:00

First, create two directories:

screenshot

Create C:\lcow, which will be used as scratch space for Docker while preparing the containers.

screenshot

Also create C:\Program Files\Linux Containers. This is where the Ubuntu container image will live.

You will need to give this folder extra permissions to allow Docker to use the images from it. Run the following Powershell script in an administrator Powershell window:

param(
[string] $Root
)
# Give the virtual machines group full control
$acl = Get-Acl -Path $Root
$vmGroupRule = new-object System.Security.AccessControl.FileSystemAccessRule("NT VIRTUAL MACHINE\Virtual Machines", "FullControl","ContainerInherit,ObjectInherit", "None", "Allow")
$acl.SetAccessRule($vmGroupRule)
Set-Acl -AclObject $acl -Path $Root

Save this file as set_perms.ps1 and run it:

TIP You may need to run ‘Set-ExecutionPolicy -Scope process unrestricted’ to be allowed to run unsigned Powershell scripts.

C:\Users\mathi\> .\set_perms.ps1 "C:\Program Files\Linux Containers"
C:\Users\mathi\>

Now, copy the Ubuntu container image .vhdx file that was decompressed at the previous step to uvm.vhdx under C:\Program Files\Linux Containers.

More Docker preparation

Duration: 2:00

Docker for Windows requires some pre-release features in order to work with Hyper-V isolation. While these features are not yet available in the Docker CE installation that was done previously, the necessary files can be downloaded from master.dockerproject.org.

Retrieve dockerd.exe and docker.exe from master.dockerproject.org, and put the two programs somewhere safe, such as in your own folder. They will be used to start the Ubuntu container in the next step.

Run an Ubuntu container on Hyper-V

Duration: 3:00

You’re now ready to start your container. First, open a Command-line prompt (cmd.exe) as Administrator, and start dockerd.exe with the right environment:

C:\Users\mathi\> set LCOW_SUPPORTED=1
C:\Users\mathi\> .\dockerd.exe -D --data-root C:\lcow

Docker already running?
If the Docker installer sets Docker to run automatically at boot, you may need to quit the already running daemon, via its toolbar icon, before running the above commands.

Then, start a Powershell window as Administrator; and run docker.exe, instructing it to pull the image for your container:

C:\Users\mathi\> .\docker.exe pull ubuntu

screenshot screenshot

We can now finally start the container. Run docker.exe again, and tell it to run the new image:

C:\Users\mathi\> .\docker.exe run -it ubuntu

screenshot

Congratulations! You have successfully set up your system to use containers with Hyper-V isolation on Windows, and have run your very own Ubuntu container.

Getting help

Duration: 1:00

If you need some guidance getting started with the Ubuntu container images for Hyper-V, or if you get stuck, help is always at hand:

1 Like

Dockerd.exe on https://master.dockerproject.org/ is only 1.8MB now and my anti virus is reporting that it’s a virus.