Running containers from Ubuntu on Windows

Original author: Dustin Kirkland
  • Transfer
  • Tutorial
Hello, Habr! A week ago, I told you about a new feature that is available in the preliminary releases of Docker and Windows Server / Windows 10 - the launch of Linux containers with Hyper-V isolation, similar to Windows containers with Hyper-V isolation. In this walkthrough, we will talk about a similar launch of containers with Ubuntu in this environment.



Introduction


As I wrote before kat, Docker containers can now be run on Windows 10 and Windows Server using Ubuntu as a hosting environment. In other words, thanks to the joint use of Docker technology and Hyper-V virtualization in Windows, you can run your own Linux-based applications in Windows using - Ubuntu!



Requirements


1. You will need an x86 PC with a 64-bit processor and 8 GB of RAM running Windows 10 or Windows Server.

2. Run Linux containers for Hyper-V: only members can pre-Windows program evaluation . This program allows you to test pre-releases of software and future versions of Windows.

3. If stability and privacy are important to your deployment (Windows Insider allows Microsoft to collect usage information), you'd better wait for the Windows 10 Fall Creator Update to be released in October 2017. In this release, Docker with Hyper-V will be available without the need for participation in her.



4.You will also need the latest release of Docker, which can be downloaded from here: http://dockerproject.org .

5. Finally, you need to make sure that you have installed the program to unzip the Ubuntu host container image, for example, 7-Zip or XZ Utils .

How to join Windows Insider


If you are already a member of this program, proceed to the next step.

Stage I :

1. Open the following link in your web browser:

https://insider.windows.com/en-us/getting-started/ .

2. To register, log in using the same Microsoft account that you use to log in to Windows 10, and click on the link Register your personal account on the start page of the Windows Insider Program. Confirm your agreement to complete the registration.

3.Now you need to open Settings in the Start menu of Windows 10, select Updates & Security, and then the Windows Insider Program in the menu on the left.



4. If necessary, click the Fix me button if Windows displays a warning: Your Windows Insider Program account needs attention (Your account in the Windows Insider Program requires attention).

Stage II :

1.In the Windows Insider Program, click Get Started. If your Microsoft account is not associated with your copy of Windows 10, log in when prompted and select the account that you want to associate with the installed copy of the operating system.

2. Now you can choose what content you want to receive as a member of the Windows Insider Program. To ensure the isolation capabilities of Hyper-V that Docker requires are available, select Fast. Double-click Confirm, then let Windows restart your computer. After a reboot, you will likely have to wait for the installation of a certain number of updates to complete before proceeding to the next step.



Install Docker for Windows


1. Download Docker for Windows from the Docker Store .



2. After downloading, complete the installation and reboot the system when prompted.



3. After rebooting, Docker will start. Docker uses the Hyper-V feature, so if necessary it will ask you to enable it and reboot. Click OK to enable Docker to enable Hyper-V and reboot the system.



Download the Ubuntu Container Image


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

2. Unzip the downloaded image using 7-Zip or XZ Utils:
C:\Users\mathi\> .\xz.exe -d xenial-container-hyper-v.vhdx.xz


Prepare your container environment


1. First create two directories.



2. Create the directory C: \ lcow , which will be used as the temporary files area for Docker when preparing containers.



3. Also create the C: \ Program Files \ Linux Containers directory . It will store the image of the Ubuntu container.

4. You will need to assign additional permissions to this directory so that Docker can use the images stored in it. Run the following Powershell script in the Powershell admin 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 the command Set-ExecutionPolicy -Scope process unrestrictedto run unsigned Powershell scripts.


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


5. Now copy the file with the Ubuntu container image ( .vhdx ) unzipped in the previous step, name it uvm.vhdx and put it in the C: \ Program Files \ Linux Containers directory .

Additional Preparatory Steps for Docker


1. Docker for Windows requires some features from the preliminary version to work with Hyper-V isolation tools. These features are not yet available in the previously installed Docker CE, but you can download the necessary files from the website http://master.dockerproject.org .



2. Download the dockerd.exe and docker.exe files from http://master.dockerproject.org and save them in a safe place, for example, in your own directory. You will need them to launch the Ubuntu container in the next step.

Run Ubuntu Container in Hyper-V


1. Now you are ready to launch your container. To get started, open the command line interface (cmd.exe) as an administrator and run dockerd.exe in the desired environment.

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

2. Then open the Powershell window as administrator and run docker.exe to download the image for your container.

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



3. Finally, it is time to start the container. Run docker.exe again and ask the system to deploy a new image.

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



Congratulations! You have successfully configured your system to work with containers with Hyper-V isolation on Windows and launched your own Ubuntu container.

Help


If you need help getting started with Ubuntu container images for Hyper-V or you are having problems, support is always there:


Also popular now: