Your submission was sent successfully! Close

Thank you for contacting us. A member of our team will be in touch shortly. Close

You have successfully unsubscribed! Close

Thank you for signing up for our newsletter!
In these regular emails you will find the latest updates about Ubuntu and upcoming events where you can meet our team.Close

Run Linux containers on Windows

1. Overview

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.


2. Requirements

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


3. Install Docker for Windows

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


4. Download the Ubuntu container image

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

5. Prepare the container environment

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.


6. More Docker preparation

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.


7. Run an Ubuntu container on Hyper-V

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.


8. Getting help