Can Windows containers be hosted on Linux?
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.
Running Linux container in windows
It's not really that complicated. For example, when you use Docker Desktop
for Windows, you can choose between using Windows containers
or Linux containers
. If you choose to run Linux containers
on Windows, there are a couple of things happen in the background, but, Docker Desktop
does that for you:
Hyper-V
supervisor need to be enabled on the windows machine- Then an
Hyper-V
Linux image is downloaded - That machine is started on
Hyper-V
and works as the newhost
for yourLinux containers
So with that in place, when you build or run new docker
images, all those instructions and commands run on these Linux
machine.
Also, the containers have an operative system
but a really simple one, that's why they are so lightweight, if you need anything else that the base image doesn't have (maybe a system call or something), that container can use the host kernel to run those instructions(the host share the kernel with the running containers). It's a really good way to start with docker, to know how it works internally.
This might help to explain how it works:
Source: https://www.docker.com/whatisdocker/
Running windows container on linux host
Unlike other Virtual computing systems like Virtual Box or VMWare, Docker images are small and not fully complete stand alone entities.
The Docker image does not include the OS kernel, instead it uses the kernel of the Docker host
This makes the images very light weight, but it also means you won't be able to run a Windows image on a Linux host.
Related Topics
Getting Android Sdk Tools to Work on Raspberry Pi
Crontab - Simple Echo Not Running
Difference Between Arm-None-Eabi and Arm-Linux-Gnueabi
What Is Eof!! in The Bash Script
Gnu Linker: Alternative to -Version-Script to List Exported Symbols at The Command Line
Angular Cli App Not Running When Deploying to Linux App Service
How to Build Git with Static Linking
How to Get My Cuda Specs on a Linux Machine
Bash: Split Stdout from Multiple Concurrent Commands into Columns
Implicit Declaration of Function 'Create_Proc_Entry'
Sudo User Not Using Same Node Version
How to Set Control Register 0 (Cr0) Bits in X86-64 Using Gcc Assembly on Linux
Fork() and Stdout/Stderr to The Console from Child Processes