Running Docker Windows and Linux Containers Simultaneously


Many of you with familiarity with Docker for Windows know how you currently have to switch between running either Windows or Linux Containers. In the following post, Premier Developer Consultant Randy Patterson teaches us how to combat this limitation and run Docker Windows and Linux Containers simultaneously on the same host.


Starting with Docker for Windows version 18.03.0-ce-win59 the Linux Containers on Windows (LCOW) is available as an experimental feature. Previously, you could get LCOW only on the Edge or Nightly Build Channels. For people like me who need a stable version of Docker for Windows, this feature was not available until now.

Docker for Windows currently allows you to switch between running Windows or Linux Containers but not both. Linux containers were hosted in a Linux Virtual Machine making it convenient for testing purposes but not production. LCOW will make it possible to have an application that mixes Linux and Windows containers together on a single host.

What you Need

In order to use the new LCOW feature, you will need the latest version Docker for Windows and have the Experimental Features enabled:

1. Docker for Windows version 18.03.0-ce-win59 or greater

    image

2. Experimental Features enabled

    a. Docker -> Settings –> Daemon

        clip_image004

Let's Get Started

With Docker for Windows started and Windows containers selected, you can now run either Windows or Linux Containers simultaneously. The new --platform=linux command line switch is used to pull or start Linux images on Windows.

docker pull --platform=linux ubuntu 

image

Now start the Linux container and a Windows Server Core container.

docker run --platform=linux -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

docker run -d microsoft/windowsservercore ping -t 127.0.0.1

image

Both containers are running on a single host.

If you list your local image cache you’ll see a mixture of both Windows and Linux images. To determine the operating system an image requires you can use docker inspect and filter on the “Os” property.

docker inspect --format '{{.Os}}' ubuntu

image

Conclusion

Running Windows and Linux containers simultaneously on the same host is an interesting new feature in Docker with lots of possibilities. However, this is an experimental feature and may have some issues. One known problem is volumes are not stable especially when mapping between Linux and Windows file systems. This can cause some containers that rely heavily on volumes to fail to load. Furthermore, tooling support is not yet complete. For example, Docker-Compose and Kubernetes cannot yet mix Windows and Linux containers. Microsoft is currently tracking issues here and feature progress can be tracked at the Github site here.

Comments (7)

  1. Wael Kdouh says:

    Great read. Thanks for sharing.

  2. Radu says:

    I tried running the “docker pull –platform=linux ubuntu” but I keep getting:
    Using default tag: latest
    Error response from daemon: invalid platform: invalid platform os “linux”

    triple checked that I have the right version, and that it’s in experimental.

    1. Joshua Buss says:

      This might sound weird, but try unchecking experimental options and re-checking it. When I tried that, I got an access denied error to a config file in c:\programdata\docker… When I cleared that up by making sure all those files didn’t have the read-only attr set (?!) I was able to re-check that box and then docker came up with the new LCOW support.

    2. FredMurphy says:

      I find that this works at home (current Windows 10 1803) but not at work where we’re on Windows 10 Enterprise LTSB (i.e. 1607). I suspect that mixed platform is not working with the earlier version of Windows 10.

      1. Randy Patterson says:

        Correct, You need Windows 10 Fall Creators Update or Windows Server, version 1709 or greater.

  3. James Royer says:

    If you inspect the image use ‘{{.Os}}’.
    If you inspect the container, use ‘{{.Platform}}’.

    docker inspect –format ‘{{.Platform}}’ container_name

  4. Renato Golia says:

    Apparently no support for CHMOD operations… I cannot get a rabbitmq container to properly start

    docker run -P –platform linux rabbitmq:management

Skip to main content