How to Run 🐧 Linux Containers on Windows Server 2019

Save to My DOJO

How to Run 🐧 Linux Containers on Windows Server 2019

Hello again everyone! This article will serve as part 5 of our “Definitive Guide to Containers for MSPs” series. Once again, this series is focusing on the new containerization technologies entering the industry today and looking at them through the lens of an MSP.

Thus far we’ve done quite a bit of how-to, and we’re going to continue to work on the how-to question for the next few segments. The reason being, when we start talking about things like pricing, service delivery, and on-going support, you need to have a strong grasp of what’s involved in the platform, so you can make informed decisions at that point. With that in mind we’re going to look at docker itself for another segment or two, and then we’ll start getting into container orchestrators like Kubernetes.

Let’s see what we’ve talked about thus far.

The Definitive Guide to Containers for MSPs

Part 1 – What are Containers?

Part 2 – Platforms for Running Containerized Workloads

Part 3 – Introduction to Docker

Part 4 – 4 Pro Tips when Working with Docker

For this segment specifically, I wanted to cover how to run Linux containers on Windows Server 2019. I came up with this idea as I was prepping for our latest webinar that centered around demos with Windows Server 2019. While it’s easy enough to run containers on Windows 10 as we did in Part 3, it’s more difficult to do it on a VM where there is no GUI, and you can’t simply install docker for Windows.

So, let’s take a look at how the installation process works, and then we’ll proceed with running a container on top of it. Once this is complete, you’ll have everything you need to run Linux and Windows containers on Windows Server (assuming you’ve read the previous segments. Let’s get Started.

How to Install Docker Enterprise Edition Preview on Windows Server 2019

In prepping for this article, I started with a freshly installed Windows Server 2019 box. I used the GA Evaluation media to install the OS, then I upgraded to the latest Nov. build using Windows Update. In our previous segments we installed the Community edition of Docker. For this particular feature, we need to install Docker Enterprise Edition and the preview release at that.

First off, if you’re using the same box as you did in previous segments you’ll want to remove the version of Docker we installed with the DockerMSFTProvider in PowerShell.

NOTE: If you’re starting with a fresh server you can skip this step.

To Remove the previous version of Docker run the below command in an elevated PowerShell window:

Uninstall-Package -Name docker -ProviderName DockerMSFTProvider

Then reboot the box.

Now that we have a clean slate we can install the needed version of Docker to run Linux Containers. You can walk through the how-to below, or scroll down to watch the video.

NOTE: We’re going to be installing a testing build of the docker engine. While it’s fine for testing and learning, I would highly suggest waiting until a stable version is released prior to using it in production.

NOTE: It is required to have the Hyper-V Role installed in order to install the Docker Enterprise Edition preview. If this is a testing VM, make sure you enable nested virtualization.

To install the current preview build of Docker Enterprise Edition we need to run the below:

Install-Module DockerProvider

Then

Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview

Reboot your machine once again.

See it in action!

How to Install Docker Enterprise Edition Preview on Windows Server 2019

How to Configure Docker Enterprise Edition to Run Linux Containers

Out of the box, this install of Docker will run Windows Containers. In order to switch back and forth between Windows and Linux containers you need to run the below commands:

To switch to Linux Containers

[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")
Restart-Service docker

To switch back to Windows Containers

[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", $null, "Machine")
Restart-Service docker

Simply switch to whichever mode meets your needs at the given time.

Running Linux Containers on Windows Server 2019

After installing the Docker Enterprise Edition Preview and configuring it to run Linux containers we can use some of the syntax that we covered in previous sections to pull and run a container

Assuming you’ve switch to Linux mode, the below should work. Let’s first pull the latest Debian Linux container image:

NOTE: You can walk through the how to below, or scroll down to watch the video

Docker pull Debian

Then let’s run it in interactive mode and run a text-based app really quick just to make sure it works.

Docker run -it --name Debian_test Debian

Once in the prompt running the below will show us which version of the linux kernel is in use

Uname -r

Finally let’s install elinks, a text based web browser, using Debian’s packaging utility Apt

Apt-get update

Apt-get install elinks

Then let’s open google in elinks:

Elinks https://www.google.com

Hopefully, it should be working!

See it in Action!

Running Linux Containers on Windows Server 2019

Wrap-Up

There you have it! You’ve successfully run a Linux container on top of Windows Server 2019. Pairing this with what we’ve done in the previous segments should have you prepared to run both Windows and Linux containers with docker. Knowing this, we’ll cover just a few more advanced docker items in the next post before getting into container orchestrators.

If you had troubles with this or have questions on use-case, or just have a general comment, be sure to let me know in the comments section below!

Until next time!

Altaro O365 Backup for MSPs
Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

29 thoughts on "How to Run 🐧 Linux Containers on Windows Server 2019"

  • Frank says:

    Hi Andy,

    What is version of Docker installed when requesting the preview version?

    Thanks,
    Frank

  • Thanks a lot for the how-to and I would like just to point out there might be a missing step for the fresh install: adding the LCOW image.

    In the LCOW github page (https://github.com/linuxkit/lcow), it’s referenced under the “Setup” section how to download the LCOW image and where to put it.

    Without this image, the Linux based images will throw an error (or at least that’s what I faced).

    Hope this helps and keep the excellent work!

    Nuno

    • Very Strange…. I didn’t run into this particular issue. I suspect the image exists by default in the Enterprise Edition Preview of Docker, which is what I used for this howto, but I don’t know that for sure. I’ll research some more and I’ll be sure to post back on that either here, or in a future segment of the series. Thanks for the info!

      • Hung says:

        Hi Andy,

        it is great instructions. I followed them exactly and it is ok to pull the windows’ images. However, when I pull the linux’s images, it gave me and error

        This is the error:

        **************
        docker pull centos
        Using default tag: latest
        latest: Pulling from library/centos
        8ba884070f61: Pulling fs layer
        8ba884070f61: Verifying Checksum
        8ba884070f61: Download complete
        docker : failed to register layer: failed to start service utility VM (applydiff dbdb990abb6f3892f0e8df339aeaac7f9da8448f971af86ee1a5de7a7b781e65): container
        dbdb990abb6f3892f0e8df339aeaac7f9da8448f971af86ee1a5de7a7b781e65_svm encountered an error during CreateContainer: failure in a Windows system call: A connection could not be established with the container or virtual
        machine. (0xc0370108) extra info: {“SystemType”:”container”,”Name”:”dbdb990abb6f3892f0e8df339aeaac7f9da8448f971af86ee1a5de7a7b781e65_svm”,”Layers”:null,”HvPartition”:true,”HvRuntime”:{“ImagePath”:”C:\\Program Files\\Linux
        Containers”,”LinuxInitrdFile”:”initrd.img”,”LinuxKernelFile”:”bootx64.efi”},”ContainerType”:”linux”,”TerminateOnLastHandleClosed”:true}
        + CategoryInfo : NotSpecified: (failed to regis…leClosed”:true}:String) [], RemoteException
        + FullyQualifiedErrorId : NativeCommandError
        **************

        I did run the command to switch to linux container

        [Environment]::SetEnvironmentVariable(“LCOW_SUPPORTED”, “1”, “Machine”)

        Why? Please assist me in this

  • imran says:

    i did exactly as you have done over here for running linux containers on windows server 2016, but after restarting docker service or restarting computer, changes are not getting reflected if use docker version, it still says experimental feature “false” which needs to be true in order to linux containers, following are actions and there errors (these actions and errors are coming even after following steps describe over here and i am using AWS cloud windows server 2016 with Full containers image)
    command: docker run –rm –platform linux busybox echo hello_world
    error: “–platform” is only supported on a Docker daemon with experimental
    features enabled

    command: docker pull ubuntu
    error: Using default tag: latest
    latest: Pulling from library/ubuntu
    no matching manifest for unknown in the manifest list entries
    command: docker pull fxlabs/bot:latest
    error: latest: Pulling from fxlabs/bot
    image operating system “linux” cannot be used on this platform

    what needs to be done to make it run linux containers, basically make experimental feature “true” in aws cloud windows server 2016 docker (EE).
    Is there something needs to be done in security group on aws side or in windows server 2016 group policy, firewall

    • Hi Imran!

      Sounds like you may not have installed Docker using the -RequiredVersion Parameter

      You’ll have to remove your existing version of Docker and reinstall the experimental version

      When you install docker make sure you use the below commands

      Install-Module DockerProvider

      Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview

  • Callum says:

    Hi Andy

    Thanks for the great post!

    I’ve been following through this myself but I’m getting stuck when trying to push my Linux container to my Azure Container Repository.

    I get the following error when pushing – open \tmp\b18abd5adacb7943b685869de1480bde160857fc250f33cccb50ed958bfadcd6-mount\usr\share\dotnet\LICENSE.txt: The system cannot find the path specified.

    Have you been able to push containers to a repository?

    Any help would be greatly appreciated thanks!

  • Peter says:

    Hi,
    every linux container pull stucks at “Download complete”. Have to press CTRL+C to cancel the process.

  • Andrew Sumner says:

    I’ve been trying to set this up on a Windows 2016 server that doesn’t have internet access. I’ve:

    1. installed Docker EE version 19.03.1 (preview
    2. registered the service using “dockerd –experimental –register-service”
    3. set Environment variable LCOW_SUPPORTED=1
    4. “docker version” gives me:
    Client: Docker Engine – Enterprise
    Version: 19.03.1
    API version: 1.40
    Go version: go1.12.5
    Git commit: f660560464
    Built: 07/25/2019 20:59:52
    OS/Arch: windows/amd64
    Experimental: false

    Server: Docker Engine – Enterprise
    Engine:
    Version: 19.03.1
    API version: 1.40 (minimum version 1.24)
    Go version: go1.12.5
    Git commit: f660560464
    Built: 07/25/2019 20:57:41
    OS/Arch: windows/amd64
    Experimental: true

    However, when I attempt to pull the debian package (using artifactory as a proxy) using “docker pull docker.artifactory2.company.co.nz/debian” I get:

    Using default tag: latest
    latest: Pulling from debian
    no matching manifest for windows/amd64 10.0.14393 in the manifest list entries

    Where have I gone wrong…?

    Looking at https://download.docker.com/components/engine/windows-server/index.json the last preview version is “17.10.0-ee-preview-3”. That is two major releases and 2 years behind, so I’m assuming that this is too old to use now…

    • Hi Andrew! As you pointed out, there have been quite a lot of changes in containers on Windows Server since this article was written. I’ll be updating this entire series in the near future, and I’ll be sure to address this as part of that update. Thanks!

  • KOSTIANTYN KHOMKO says:

    Hello.
    Please advise how to add GUI to windows server 2019?
    Thanks.

  • reader says:

    Thank you for your detail doc .
    In my case , everything goes well ,except the last step : it will not extact the docker image , after downloading the image , it hangs

    PS C:\Users\Administrator> docker run -it –rm ubuntu /bin/bash
    Unable to find image ‘ubuntu:latest’ locally
    latest: Pulling from library/ubuntu
    da7391352a9b: Download complete
    14428a6d4bcd: Download complete
    2c2d948710f2: Download complete

    hanging hanging hanging here

    At last , I switch to docker desktop for win 2019 .
    And surprisingly, docker desktop (latest version ) works on win 2019.

    The winver of win 2019 is “version 1809 os build 17763.737”

    https://github.com/docker/for-win/issues/6769#issuecomment-679286755

    • Hi! Yeah there were some bugs in early versions of Docker on Windows 10. I’ll be updating this series sometime in the near future and will be sure to address this in a bit more detail. Thanks!

  • Eirik M says:

    Done everything you said, but docker version insists that it should build windows images instead of Linux images:
    Server: Docker Engine – Enterprise
    Engine:
    Version: 19.03.12
    API version: 1.40 (minimum version 1.24)
    Go version: go1.13.13
    Git commit: f295753ffd
    Built: 08/05/2020 19:26:41
    OS/Arch: windows/amd64
    Experimental: true

    How can I get it to build Linux images? This is so frustrating.

    • Hi Eirik! Yeah, there were some bugs I’ve encountered in various versions and the process has changed slightly as well since this post was published. I’ll be updating this series sometime in the near future and will be sure to address this in a bit more detail. Thanks!

  • Julio says:

    Hello Andy.

    Found this method in Docker Success page:
    https://success.docker.com/article/how-to-enable-linux-containers-on-windows-server-2019

    I have tested them both and even when both are experimental and so, improvable, this “new” method in the Docker page has given to me better results.

    Thanks
    Julio

    • Hi Julio! Thanks for sharing this link! Much has changed with containers on Windows 10 since this article was posted. I’ll be during a future update on this series and I’ll be sure to address this. Thank you!

  • Shanta says:

    Hi, I have setup Docker EE on a Windows Server 2019 VM. I can pull Linux based images but I cannot build images or run containers. Based on the research that I have done, I need to enable nested virtualization. How do I do this from the VM itself – it’s a corporate environment & the VM is running on a Nutanix stack.

    • Hi Shanta! You’d have to enable nested virtualization at the Nutanix layer. Sadly that’s outside the scope of this blog. Check with your Nutanix support vendor on this if it’s still a pending issue.

Leave a comment

Your email address will not be published.