Can Windows containers be hosted on Linux?
Asked Answered
B

10

410

Is it possible to run Windows containers on Linux? The scenario is based on an application written in .NET (old net) and the Linux user that wants to run this with Docker needs to provide a net462 written API on the localhost.

I am using the beta version of Docker Desktop for Windows.

If no, then why can Windows run Linux containers and not vice-versa?


As some time has passed and this question is a popular one, I'd like to add one note here that the workaround is to use the new .NET Standard. It allowed me to pack the 4.6.2 framework into a new library.

Bascomb answered 10/2, 2017 at 11:44 Comment(17)
Not possible - To build and run Windows containers, a Windows system with container support is required.Dispeople
Ok, but why then Windows can run linux containers? There is no vice-versa for now?Bascomb
No vice-versa for any OS for ever. Containers are NOT full Virtualisation mechanisms. If you want to avoid rewriting your application, you'll have to run it on a VM with a Windows guest. Or rewrite the application in .NET CoreDissect
@Sebastian506563 because docker runs VirtualBox virtualization behind the scenes to make Linux containers to run on Windows. I would guess theoretically it will be possible the other way as well, just docker did not implement it.Rumilly
@GSA not any more. It uses HyperV now, but it's still a VM. Docker doesn't mix OSs in any way. It's still the same OS running inside and outside the containerDissect
With VMs, each vm has its own operating system. With containers, there is base OS image and each container is adding a new thin layer on top the base. In docker's this base OS linux based. i.e. your windows container cannot user the base as it is different. blog.risingstack.com/…Dobbs
@PanagiotisKanavos please compose answereBascomb
@PanagiotisKanavos There is nothing preventing docker in theory running Windows virtualize OS in Linux and instantiating Windows container in process isolation mode. Regardless which hypervisor they use in Windows (hyper-v or Virtual Box) they do the same thing for Linux running in WindowsRumilly
@GSA except the missing OS Kernel, libraries and servicesDissect
@PanagiotisKanavos Docker currently runs virtual Linux inside Windows and run Linux container on top of it. It can easily do the same on Linux. That is stand up Windows virtual OS, install docker on it and remotely manage like it does currently on Windows. Nothing will be missing. Docker does exact the same thing on Windows currently and hence this question. Issue will be licensing obviously since docker will need to have full blown virtual OS for this work, it does not have this issue with Linux and hence may be discrepancyRumilly
@GSA it runs a Linux VM which is used as host. Containers run inside that VM. You can't use Linux containers outside the Linux VM. Just try it. Open up Hyper-V Manager and check the name of the VM. It's that VM that offers Linux support, not some container featureDissect
@PanagiotisKanavos. Correct docker runs Linux container on Windows hosts by creating Linux virtual OS on Windows host. It can theoretically do in reverse. That is run Windows virtual OS on Linux host and create Windows container inside Windows virtual OS running on Linux host. Nothing prevents docker from doing it except for licensing and management overhead. In fact I run Windows containers currently in Windows virtual OS which is hosted on Vmware hyper-visor which is Linux based.Rumilly
You might wanna see this question, the answers have some explanation related to your question: #16047806Dobbs
Did you try to run you net462 under mono? Do this if its not possible do migrate to netstandard/core.Staten
Windows doesn't "run" Linux containers, it emulates them. Same can be achieved in opposite way. But since Linux is extremely light compared to Windows, it is much more easier (and make sense) to implement Linux emulator rather than Windows one.Rimbaud
Today, it is clearly possible. I recently succeeded in containerizing Windows Guest using QEMU and Docker. github.com/gnh1201/docker-qemu/wiki/Windows-GuestLineman
There's an open issue about that on Podman trackerKelbee
F
329

TL;DR:

Q: Can Windows containers run on Linux?

A: No. They cannot.

Containers are using the underlying operating system resources and drivers, so Windows containers can run on Windows only, and Linux containers can run on Linux only.

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

A: Docker for Windows allows you to simulate running Linux containers on Windows, but under the hood a Linux VM is created, so still Linux containers are running on Linux, and Windows containers are running on Windows.

Bonus: Read this very nice article about running Linux docker containers on Windows.

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

A: It depends. Consider the following recommendations:

  • If it is possible, move to .NET Core. Since .NET Core brings support to most major features of .NET Framework, and .NET Framework 4.8 will be the last version of .NET framework

  • If you cannot migrate to .NET Core - As @Sebastian mentioned - you can convert your libraries to .NET Standard, and have two versions of the application - one on .NET Framework 4.6.2, and one on .NET Core - it is not always obvious. Visual Studio supports it pretty well (with multi-targeting), but some dependencies can require extra care.

  • (Less recommended) In some cases, you can run Windows containers. Windows containers are becoming more and more mature, with better support in platforms like Kubernetes. But to be able to run .NET Framework code, you still need to run on base image of "Server Core", which occupies about 1.4 GB. In same rare cases, you can migrate your code to .NET Core, but still run on Windows Nano server, with an image size of 95 MB.

Leaving also the old updates for history

Update 2: 08.2018

If you are using Docker-for-Windows, you can run now both Windows and Linux containers simultaneously: Running Docker Windows and Linux Containers Simultaneously

Bonus: Not directly related to the question, but you can now run not only the Linux container itself, but also an orchestrator like Kubernetes: Kubernetes is Now Available In Docker Desktop Stable Channel

Updated at 2018:

Original answer in general is right, BUT several months ago, Docker added experimental feature LCOW (official GitHub repository).

From this post:

Doesn’t Docker for Windows already run Linux containers? That’s right. Docker for Windows can run Linux or Windows containers, with support for Linux containers via a Hyper-V Moby Linux VM (as of Docker for Windows 17.10 this VM is based on LinuxKit).

The setup for running Linux containers with LCOW is a lot simpler than the previous architecture where a Hyper-V Linux VM runs a Linux Docker daemon, along with all your containers. With LCOW, the Docker daemon runs as a Windows process (same as when running Docker Windows containers), and every time you start a Linux container Docker launches a minimal Hyper-V hypervisor running a VM with a Linux kernel, runc and the container processes running on top.

Because there’s only one Docker daemon, and because that daemon now runs on Windows, it will soon be possible to run Windows and Linux Docker containers side-by-side, in the same networking namespace. This will unlock a lot of exciting development and production scenarios for Docker users on Windows.

Original:

As mentioned in comments by @PanagiotisKanavos, containers are not for virtualization, and they are using the resources of the host machine. As a result, for now a Windows container cannot run "as-is" on a Linux machine.

But - you can do it by using VM - as it works on Windows. You can install a Windows VM on your Linux host, which will allow to run Windows containers.

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

Also, this answer provides more details.

Firefly answered 12/2, 2017 at 7:36 Comment(8)
The linked answer does not actually provide any details on this - it just explains how to run Linux containers on Windows (the inverse). It is possible to run Docker inside a Windows VM, but you need nested virtualization support for this. This means it works with VMware, but not Virtualbox.Pyrenees
A lot of words in the answer but it doesn't seem to answer the question.Oys
Its not answer to the question. It should not be so highly rankedRosannarosanne
This is NOT an answer to this question. Running docker on Linux is MARKEDLY different from running docker on Windows. Why is this marked as an answer?\Tier
Containers = efficiently run diff isolated apps (that were built for a specific OS), less memory, disk space, overhead, more efficient hardware utilization VMs = use case ..run whole OS's for various use cases...,hardware utilization is good (I don't need to buy a diff machine for each OS..if I actually need multiple OS for my use case), but hard utilization not as great compared to containers. Great video by CTO of Joyent: youtube.com/watch?v=coFIEH3vXPwLeningrad
And on windows you cannot communicate between windows and linux containers. Here's the full list of limitations docs.docker.com/docker-for-windows/networking/…Bohrer
It appears you can now run Microsoft Windows as a Docker based container - see Windows base os images. According to the page these containers must run on a Windows host but they appear to be Docker images.Hoggish
Hypothetically, what if a Windows-container engine such as Containerd was able to run on Wine?Knorring
F
35

No, you cannot run Windows containers directly on Linux.

But you can run Linux on Windows.

Windows Server 2016 and above comes packaged with a base image of the Ubuntu OS (after the September 2016 beta service pack). That is the reason you can run Linux on Windows and not otherwise. Check it out here. Finally, Linux Containers Could Run on Windows with Docker’s LinuxKit

You can change between OS containers, Linux and Windows by clicking Docker in the tray menu.

Enter image description here

Enter image description here

Falcate answered 20/8, 2017 at 0:9 Comment(3)
The OP is looking to run Windows containers on Linux servers instead, so this one does not answer the question. But I don't like people that gives downvote without a comment, so I'm giving an upvoteUyekawa
@Karthikeyan V: Because it's not an answer to the question.Broadwater
I'm not sure what it said before but the first statement says you cant and the second one says you can. Its probably a missing or something that is confusing.Amaris
N
26

While Docker for Windows is perfectly able to run Linux containers, the converse, while theoretically possible, is not implemented due to practical reasons.

The most obvious one is, while Docker for Windows can run a Linux VM freely, Docker for Linux would require a Windows license in order to run it 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 may not be an impracticable size, but it is much more cumbersome than the Linux on Windows counterpart.

While it is certainly possible for someone to sell a Docker for Linux variation bundled with a Windows license and ready to run Windows containers under Linux (and I don't know if such product exists), the bottom line is that you can't avoid paying Windows vendor lock-in price: both in money and storage space.

Nameplate answered 8/5, 2019 at 12:57 Comment(0)
R
24

Solution 1 - Using VirtualBox

As Muhammad Sahputra suggested in this post, it is possible to run Windows OS inside VirtualBox (using VBoxHeadless - without graphical interface) inside a Docker container.

Also, a NAT setup inside the VM network configurations can do a port forwarding which gives you the ability to pass-through any traffic that comes to and from the Docker container. This eventually, in a wide perspective, allows you to run any Windows-based service on top of Linux machine.

Maybe this is not a typical use case of a Docker container, but it definitely is an interesting approach to the problem.


Solution 2 - Using Wine

For simple applications and maybe more complicated, you can try to use wine inside a docker container.

This Docker Hub page may help you to achieve your goal.


I hope that Docker will release a native solution soon, like they did with docker-machine on Windows several years ago.

Rimbaud answered 10/1, 2019 at 19:3 Comment(0)
J
19

Containers use the OS kernel. Windows containers utilize processes in order to run. So theoretically speaking, Windows containers cannot run on Linux.

However there are workarounds utilizing VMstyle solutions.

I have found this solution which uses Vagrant and Packer on Mac, so it should work for Linux as well: https://github.com/StefanScherer/windows-docker-machine

This Vagrant environment creates a Docker Machine to work on your MacBook with Windows containers. You can easily switch between Docker for Mac Linux containers and the Windows containers.

Running bash commands

Enter image description here

building the headless Vagrant box

$ git clone https://github.com/StefanScherer/packer-windows
$ cd packer-windows

$ packer build --only=vmware-iso windows_2019_docker.json
$ vagrant box add windows_2019_docker windows_2019_docker_vmware.box

Create the Docker Machine

$ git clone https://github.com/StefanScherer/windows-docker-machine
$ cd windows-docker-machine
$ vagrant up --provider vmware_fusion 2019

Switch to Windows containers

$ eval $(docker-machine env 2019)
Juvenilia answered 1/4, 2019 at 11:47 Comment(0)
W
13

Unlike virtualization, containerization uses the same host OS. So the container built on Linux can not be run on Windows and vice versa.

In Windows, you have to take help of virtualization (using Hyper-V) to have same OS as your container's OS and then you should be able to run the same.

Docker for Windows is a similar application which is built on Hyper-V and helps in running Linux Docker containers on Windows. But as far as I know, there is nothing as such which helps run Windows containers on Linux.

Wisteria answered 30/5, 2018 at 12:36 Comment(0)
H
7

You can use Windows Containers inside a virtual machine (the guest OS should match the requirements - Windows 10 Pro or Windows Server 2016).

For example, you can use VirtualBox. Just enable Hyper-V inside SystemAccelerationParavirtualization Interface.

After that, if Docker doesn't start up because of an error, use the "Switch to Windows containers..." in the settings.

Hellraiser answered 10/1, 2018 at 15:51 Comment(0)
U
3

We can run Linux containers on Windows. Docker for Windows uses the Hyper-V based Linux-Kit or WSL 2 as the backend to facilitate Linux containers.

If any Linux distribution has this kind of setup, we can run Windows containers. Docker for Linux supports only Linux containers.

Ukulele answered 25/9, 2020 at 17:50 Comment(0)
S
2

You can run SQL Server and .NET Core on Linux, and hence inside Linux containers, nowadays.

See: Microsoft SQL Server by Microsoft | Docker Hub

Also: .NET Core by Microsoft | Docker Hub

The direct answer to your question, is of course, unless there is a version compiled especially for Linux, no.

Swath answered 26/6, 2018 at 23:31 Comment(5)
This is true - but it has nothing to do with the question. Plus MS-SQL is more than just the engine (which on Linux comes without filestream or R by the way - so it's not even the entire engine).Broadwater
You have to think one step ahead... why is he asking? If he is asking because he wants to run one of these: voila.Swath
Possible. But IMHO, he's probably asking the question because he has already done that, and now he has to run things like SSRS/SSAS or some web-form control, such as ReportViewer, on Linux.Broadwater
Docker image microsoft/dotnet is for .Net Core, which is something completely different from old .Net 4.x so you can't run app designed for old .Net on .Net CoreGwynethgwynne
They are supporting .NET Core and NOT .NET - these are two completely different environments.Rimbaud
B
-4

what? why? I just installed Windows 10 PRO on VMM on my "Debian like" host ... VMM is a very old virtual machine manager... yes, with it, the host machine works slowly, but everything is fine and fast inside the virtual machine. this is a great option for using windows features in development

Baskin answered 31/10, 2022 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.