Coder Perfect

Is it possible to run Windows containers on Linux?

Problem

Is it possible to use Linux to run Windows containers? The case is centered on a.NET (old net) program and a Linux user who wishes to run it with Docker and give a net462 written API on localhost.

I’m using the Docker Desktop for Windows beta version.

If not, why can Windows containers operate on Linux but not vice versa?

This inquiry has become increasingly popular as time has passed. I’d want to point out that using the new netstandard is a workaround. It made it possible for me to include the 4.6.2 framework in a new library.

Asked by Sebastian 506563

Solution #1

TL;DR:

Is it possible to run Windows containers on Linux?

No, it isn’t. They are unable to do so.

Containers use the resources and drivers provided by the underlying operating system, hence Windows containers can only operate on Windows, and Linux containers can only run on Linux.

Q: But what about Docker for Windows? Or other VM-based solutions?

A: Docker for Windows simulates running Linux containers on Windows, but a Linux VM is constructed behind the scenes, so Linux containers continue to operate on Linux and Windows containers continue to run on Windows.

Bonus: Check out this excellent article on how to run Linux docker containers on Windows.

Q: So, if I want to run a.NET Framework 462 application in a container, what should I do?

A: It is debatable. Following are a few suggestions:

Leaving the old updates as well for historical sake.

Update 2: 08.2018

You may now run both Windows and Linux containers simultaneously if you’re using Docker-for-Windows: Simultaneously running Docker Windows and Linux Containers

Bonus: While not directly connected to the query, you can now run both the Linux container and a Kubernetes orchestrator: Docker Desktop Stable Channel Now Supports Kubernetes

Updated at 2018:

The original answer is correct in general, but Docker recently included the experimental functionality LCOW (official GitHub repository).

From this post:

Original:

Containers are not for virtualization, as @PanagiotisKanavos pointed out in the comments, because they use the host machine’s resources. As a result, a Windows container cannot run “as is” on a Linux computer for the time being.

However, because VM runs on Windows, you can do that. You can run Windows containers on your Linux host by installing a Windows virtual machine.

With it, IMHO running it this way in a production environment will not be the best idea.

In addition, this response provides extra information.

Answered by evgenyl

Solution #2

No, you can’t run Windows containers on Linux directly.

However, Linux can be run on Windows.

Windows Server 2016 has a base image of the Ubuntu operating system (after the September 2016 beta service pack). That is why you can run Linux on Windows and not the other way around. Take a look here. Finally, Docker’s LinuxKit allows Linux containers to run on Windows.

By right-clicking on the Docker in the tray menu, you can switch between Linux and Windows OS containers.

Answered by Karthikeyan VK

Solution #3

The OS kernel is used by containers. Processes are used by Windows containers to run. As a result, Windows containers cannot theoretically run on Linux.

However, VMstyle solutions can be used as a workaround.

I found a method for Mac that uses Vagrant and Packer, and it should work for Linux as well: https://github.com/StefanScherer/windows-docker-machine

Answered by workaround

Solution #4

While Docker for Windows is perfectly capable of running Linux containers, the reverse is not possible owing to practical considerations.

The most obvious difference is that although Docker for Windows can operate a Linux VM without requiring a Windows license, Docker for Linux would require a Windows license to run inside a VM.

Also, Linux is completely customizable, so the Linux VM used by Docker for Windows has been stripped down to just a few MB, containing only the bare minimum needed to run the containers, while the smallest Windows distribution available is about 1.5 GB. It’s not insurmountably large, but it’s a lot more clunky than the Linux on Windows version.

While it’s possible that someone will sell a Docker for Linux version that comes with a Windows license and is ready to run Windows containers under Linux (and I’m not sure if such a product exists), the bottom line is that you can’t avoid paying the Windows vendor lock-in price in terms of both money and storage space.

Answered by lvella

Solution #5

It is feasible to run Windows OS within a Docker container, as recommended by Muhammad Sahputra in this post (using VBoxHeadless – without graphical interface).

A NAT setup within the VM network configurations can also do port forwarding, allowing you to pass through any traffic that arrives to and from the Docker container. In the long run, this allows you to run any Windows-based service on top of a Linux machine.

Although this is not an usual use case for a Docker container, it is an intriguing solution to the problem.

You can use wine inside a docker container for simple and possibly more advanced apps.

This Docker Hub page might be able to assist you in achieving your aim.

I’m hoping Docker will release a native solution soon, similar to what they did with docker-machine on Windows a few years ago.

Answered by Slavik Meltser

Post is based on https://stackoverflow.com/questions/42158596/can-windows-containers-be-hosted-on-linux