Run Linux And Windows Containers Side-By-Side (Beta)

In this blog post, I’ll show you how to run Linux and Windows Containers Side-By-Side on the same Windows Container host.

LCOW – Linux Containers On Windows Is currently the #1 requested feature are after this feature.

Currently, LCOW Is still In beta and not supported In a production environment so please use it for dev proposes.

Requirements

To get this done, I’ll use the features below.

  • Windows 10 1709 and Docker For Windows Nightly build
  • nested virtualization enabled on the VM
  • LinuxKit Installed
Get Started

To get started, I’m Installing a Windows 10 1709 as a Virtual Machine.

The VM needs minimum 2 CPUs and 3GB of ram.

Once done, I’ll verify the version number using

Winver

Enable nested Virtualization

Once the VM Is up and running I’ll enable Nested virtualization on the VM by shutting the VM down and running the cmdlet below.

Set-VMProcessor -VMName windows1709 -ExposeVirtualizationExtensions $true
Get-VMNetworkAdapter -VMName windows1709 | Set-VMNetworkAdapter -MacAddressSpoofing On

Install Windows Containers And Hyper-V

Next, I’ll start the VM and Install Windows Containers and Hyper-V using the cmdlet below:

Enable-WindowsOptionalFeature -Online -FeatureName containers -All -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart

I’ll restart the VM once completed

Install LinuxKit

Next, I’ll Install LinuxKit which will make LCOW works on Windows by running all Linux Containers Inside a small virtual machine.

Invoke-WebRequest -OutFile "$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

Install Docker

Now, I’ll Install Docker from the nightly build project

Invoke-WebRequest -OutFile "$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, I’ll register the docker service

. $env:ProgramFiles\docker\dockerd.exe --register-service --experimental

And setup the environmental variables

[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$($env:ProgramFiles)\docker", [EnvironmentVariableTarget]::Machine)

And before running LCOW, I’ll restart the VM one more time.

Run LCOW

Next, I’ll download the Alpine Linux Image using the line below.

Note – For now we need to use the –platform switch to download Linux Images

docker pull --platform linux alpine

I’ll download the Windows Nano Server Image

docker pull microsoft/nanoserver:1709

Run Linux And Windows Containers Side By Side

Using my Nano Server Image, I’ll run a Windows Container

docker run -it -d --name nano microsoft/nanoserver:1709

I’ll also start a Linux Containers

docker run -it -d --name linux alpine

And below you can see both Linux And Windows Containers running Site By Side

docker ps

Conclusion

It looks like Microsoft and Docker are putting a lot of work to get LOCM working well on Windows and it looks like that by the end of the year LOCM will be fully supported.

Leave a Reply

Your email address will not be published. Required fields are marked *