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
2. Experimental Features enabled
a. Docker -> Settings –> Daemon
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
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
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
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.
0 comments