lcow--single Docker engine can run Linux and Windows containers at the same time!

Source: Internet
Author: User
Tags docker ps docker compose docker run windows insider

79251059

Just last week, the Lcow (Linux Containers on Windows) [1] feature was added to the official Docker Master branch. Enable this feature to run both Linux and Windows containers under a single Docker engine.
Let's take a quick look at what's going to happen with Windows 10.


    • You can use the Docker command Docker PS to list all running Linux or Windows containers.

    • Share data between a container and a host through a storage volume.

    • Containers can communicate with each other through the container network.

    • Local access is achieved by mapping the port to the host. But for now, it's only a feature of the Windows 10 1803 Preview Experience Program (Windows Insider).

Running the Linux container

Now you need to specify--platform to pull the Linux image. If you are pulling a mirror image of a multi-schema that has both Linux and Windows, you also need to specify this option.
docker pull --platform linux alpine

The mirror pull is complete and can be run without specifying the--platform option.
docker run alpine uname -a

Also, running a Linux container on Windows requires a small Hyper-V virtual machine. At the same time, the Linuxkit project provides a lcow image, please refer to: Https://github.com/linuxkit/lcow. Shared storage

Next we look at how to use a simple way to achieve data sharing between different platform containers.
The method is to bind the Linux and Windows containers to the same storage volume.
In the following example, the Linux and Windows containers share data through a shared folder of the host.


First, create a new folder on Windows 10.
cd \
mkdir host
Start the Linux container
Start a Linux container on a Windows 10 host, and mount the shared folder on the host to the/test folder of the container.
docker run -it -v C:\host:\test alpine sh

We create a new file named Hello-from-linux.txt under the/test folder.
test/hello-from-linux.txt
Start the Windows container
Start a Windows container on a Windows 10 host, and mount the shared folder on the host to the C:\test folder of the container.
docker run -i -v C:\host:C:\test microsoft/nanoserver:1709 cmd

We create a new file named Hello-from-windows.txt under the C:\test folder.
test\hello-from-windows.txt
Test results
The new files in both containers are saved in a shared folder on a Windows 10 host.
PS C:\> dir host
   Directory: C:\host
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        1/21/2018   4:32 AM             85 hello-from-linux.txt
-a----        1/21/2018   4:33 AM             46 hello-from-windows.txt

In the development process, if you need to share the configuration file or code, it is very convenient to have wood ~ mixed arrangement

It is worth mentioning that the use of Docker compose can also be mixed orchestration container. Here is an example of a mixed orchestration of Linux and window Web servers.
Version: "3.2"
Services
Web1:
Image:nginx
Volumes
-TypeBind
Source:c:\host
Target:/Test
Ports
-80:80
WEB2:
image:stefanscherer/hello-dresden:0.0.3-windows-1709
Volumes
- type: bind
Source:c:\host
Target:c:\Test
Ports
-81:3,000
Networks
Default
External
Name:nat

You can also think about how to orchestrate a Linux database and Windows Frontend, and vice versa. How to build your Lcow test environment

If you're trying to play lcow, we recommend using a Windows 10 1709 virtual machine.
Azure
I tested Lcow with a Windows 10 1709 virtual machine on Microsoft Azure. You can choose a V3 machine with nested hypervisor to run the Hyper-V container.
Containers and Hyper-V
First, enable the container and Hyper-V features:
Enable-WindowsOptionalFeature -Online -FeatureName containers -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
Linuxkit
Then, install a linuxkit image for your lcow. Here is the latest version of Linuxkit that I downloaded, and you can download it yourself from linuxkit/lcow[2.
"$env:TEMP\linuxkit-lcow.zip" "https://23-111085629-gh.circle-artifacts.com/0/release.zip"
Expand-Archive -Path "$env:TEMP\linuxkit-lcow.zip" -DestinationPath "$env:ProgramFiles\Linux Containers" -Force
Create Docker
Now you can download and install the Docker engine.
"$env:TEMP\docker-master.zip" "https://master.dockerproject.com/windows/x86_64/docker.zip"
Expand-Archive -Path "$env:TEMP\docker-master.zip" -DestinationPath $env:ProgramFiles -Force

Next, install the Docker service and turn on the experiment feature.
 . $env:ProgramFiles\docker\dockerd.exe --register-service --experimental

Immediately, configure path to use the Docker CLI.
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine)

Congratulations to you! Now it's time to restart the machine. The configuration of the container and Hyper-V is automatically updated during the restart process. If all goes well, the Docker engine should be up and running after restarting, and you can use the Docker CLI on the PowerShell terminal. The local vagrant Environment

If your vagrant has Hyper-V or VMware installed, it's more convenient. With just a few commands, you can easily build a local test environment.
You just need to download the docker-windows-box containing the LCOW environment from my github and execute the following command.
clone https://github.com/StefanScherer/docker-windows-box
cd docker-windows-box
cd lcow
vagrant up

If you do not have a vagrant base box on your Windows 10 virtual machine, the installation will be downloaded automatically. If it has already been downloaded, it will be installed only. Summarize

The next few months, with these new Docker features added to Windows,windows 10 will undoubtedly become the most attractive developer platform of the 2018.
Imagine that you use DOCKER-COMPOSE.YML to orchestrate Linux and Windows containers, debug your application in real time through visual Studio code, and so on.
If you like this post, please share it with your friends. If you want to get the latest information about Windows containers, follow the original author's Twitter @stefscherer[3].
RELATED links:
    1. https://github.com/moby/moby/pull/34859

    2. Https://github.com/linuxkit/lcow/releases

    3. Https://twitter.com/stefscherer

Original link: https://stefanscherer.github.io/sneak-peek-at-lcow/

lcow--single Docker engine can run Linux and Windows containers at the same time!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.