Getting Community Docker to Switch to Linux Containers in Windows (without relying on Docker Desktop.)

I have a very specific Docker/Windows question with very specific constraints. I hope I can find a conclusive answer ("no, it cannot be done", or "it can be done with these reproducible steps".)

I need to install the community edition of Docker, on Windows (not the licensed Docker Desktop, but the "raw" CLI).

This can be done in (the licensed) Docker Desktop using the DockerCli.exe program that comes with it. For example:

PS> .\DockerCli.exe -SwitchLinuxEngine

The need is to switch from using Windows containers to using Linux containers (in order to have dockerd pull and run some custom/legacy images that are based on Alpine.) Without this, Docker on Windows will complain as follows:

2020-09-18T03:30:24.0943834Z image operating system "linux" cannot be used on this platform

With Docker Desktop, this was no problem (just use DockerCli.exe to get the daemon to switch container strategies.)

But now that Docker Desktop requires a license, this is not an option (or it is not a preferred option.)

Unfortunately, I can't find a way to switch container strategies with just plain-vanilla docker (installed either with a direct release or via something like Scoop.)

So, my very specific question is this:

Can this be done on Windows with plain, bare-bones docker binaries, without relying on Docker Desktop, WSL2, etc? Maybe by using PowerShell to tweak the system, or using some other non-licensed and open-source CLI to do this magic?

I'm looking for a yes/no answer (and if yes, hopefully with reproducible instructions.)

If it cannot be done, I'm ok with that as long as I can document this.

Please note the strict context/constraints in which I'm framing this question.

Thanks, and have a great weekend.

PS.

I'm not looking to debate if WSL2 is good or not, or why I am not considering it as an option. Nothing wrong with WSL2, but there are operational constrains that make WSL2 a less desirable for a very specific business case (and which I'm not going to discuss here.)

Thanks.

6

1 Answer

No, this is not possible. Not without a virtual machine.

To understand why, it is first necessary to understand how containers on Linux work: By utilizing kernel functionality to isolate process trees from the host system is certain regards. Usually, a container has its own:

  • PID namespace (it cannot see “outside” processes)
  • Mount namespace (it cannot see the host filesystem)
  • Network namespace (it appears as a separate host and cannot access host’s localhost)
  • IPC (it cannot do inter-process communication with “outside” processes)

You can run Linux binaries on Windows nowadays thanks to WSL. However, WSL 1 does not use a Linux kernel and as such does not support Linux namespaces. WSL 1 cannot run Docker containers.

Docker Desktop makes use of VMs to run Linux containers “on Windows”. It supports two modes of operation: Hyper-V and WSL 2. Hyper-V is the original way Docker Desktop worked, but it is not available on Windows Home editions. WSL 2 is built on top of the Hyper-V platform under the hood. It is available on Home editions. Like the original Docker Desktop Hyper-V VM, it runs a real Linux kernel.

When you “switch to Linux” on Docker Desktop, you switch to a virtual machine running Linux.

You cannot run Linux containers on Windows. Linux containers only run on Linux.

You can replace Docker Desktop with fully open source software and achieve (with some extra work) the same CLI experience. However, a VM is absolutely totally required.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like