Like keeping baby whales in captivity, away from their natural habitat. That's what it feels like. But sometimes I guess we'll just have to club some seals and we'll have to run some Linux containers on Windows Server.

I've been using and loving Docker on Linux for quite some time now. To the point where even if I set up a small website I'll just throw some containers up there, because it became second nature, and part of the way I work.

In the back of my mind I knew Docker can be run on Mac and Windows as well with virtualization technology, and that Windows has a container project in the works. So things definitely looked promising, I never thought running Linux containers — basically the containers we all know and love — on Windows Server is a big deal.

Same same, right?

Well, I was in for a surprise. As soon as I ran the docker run command to test an nginx container I realized it's going to be a loong day. It turns out it's very easy to run some obscure Windows containers, but what good are those for me?

So, below are a few key takeaways, and pointers to help you accomplish this feat of bravery.

You cannot run Docker CE on Windows Server

Docker CE is the open source and free to use version of Docker, which runs natively on Linux, and it can run on Mac and Windows leveraging a virtual Linux environment.

When you install Docker Desktop or Docker Toolbox, it is running Docker CE on a virtual Linux instance. That version of Docker will not be available on Windows Server.

Instead what you can use is the Docker EE, or something called the Docker EE Preview package.

Windows Server Build Version Matters

You can run Linux containers on Windows Server 2016 on builds higher than 16278, with the use of LinuxKit. LinuxKit in these cases will have to be installed separately.

In version 1709 and higher they introduced the Docker EE Preview, which contains LinuxKit out of the box. Even though it's probably best if you download a new version and reinstall it.

The Experimental Flag

In Windows Server 2016 earlier than 1709, you will need to manually set the experimental: true flag in the daemon.json config that can be found in

C:\ProgramData\docker\config\daemon.json

If the file doesn't exist you'll have to create it and append the json content.

Alternatively you can run

.\dockerd.exe -D --experimental

in the folder where you have docker installed.

On Windows Server 2019, and theoretically on 2016 build >= 1709 you can toggle the support for Linux containers with one liners.

Enabling support for Linux containers:

[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")

Disabling support for Linux containers:

[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", $null, "Machine")

Remember to always restart the service:

Restart-Service docker

Make Sure to Enable HyperV

HyperV is mandatory for running Linux containers on Windows Server, don't forget to enable it and reboot your system.

You can do so with the commands below:

Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart
Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature

If you're running an Azure VM, surprise: The Instance Version Matters!

If you're getting some weird feature missing type of error, there's a good chance you're running a DSv2 instance. It has to do with the processor allocated not supporting virtualization. To be able to run this successfully, you'll need a DSv3 instance.

Use an Elevated PowerShell

This might seem intuitive, but sometimes you'll get unintuitive errors. Always make sure that you're running your PowerShell instance in Administrator mode.

Conclusion

Running Linux containers on Windows Server is not as straight forward as one might expect, and there's quite a few hoops to jump through. That said, if circumstances require you to set this up, I would say following the steps below is the easiest way to achieve this.

  • Get a DSv3 instance on Azure with a Windows Server 2019 installation
  • Connect to it via Remote Desktop Connection
  • Enable HyperV using the commands below
Enable-WindowsOptionalFeature –Online -FeatureName Microsoft-Hyper-V –All -NoRestart
Install-WindowsFeature RSAT-Hyper-V-Tools -IncludeAllSubFeature
  • Reboot the instance
  • Install Docker EE Preview using the commands below
Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
  • Reboot the instance
  • Enable Linux Container support and restart Docker using the commands below
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
Restart-Service docker
  • Test it by running a basic Linux container e.g.
docker run --name proxy -P -d nginx

That's about it, you should have it up and running. I hope this will save you some struggle. Good luck!