Can Windows Containers be hosted on linux?
Is it possible to run Windows Containers on Linux? The scenario is based on an app written in the .NET (old net) and the Linux user that wants to run this with Docker to provide a net462 written API on the localhost .
I am using beta version from 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 netstandard. It allowed me to pack 4.6.2 framework into new library.
9 Answers 9
Update3: 06.2019 Some of the comments says that the answer is not clear, I’ll try to clarify.
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 app, if I would like to run in a container?
A: It depends. Following several 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 2 versions of app — 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 servers, with an image size of 95 MB.
Leaving also the old updates for history
Update2: 08.2018 If you are using Docker-for-Windows, you can run now both windows and linux containers simultaneously: https://blogs.msdn.microsoft.com/premier_developer/2018/04/20/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 orchestrator like kubernetes: https://blog.docker.com/2018/07/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).
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 windows container cannot run «as-is» on linux machine.
But — you can do it by using VM — as it works on windows. You can install windows VM on your linux host, which will allow to run windows containers.
With it, IMHO run it this way on PROD environment will not be the best idea.
Можно ли запустить Windows приложение в Linux Docker container?
Возможно глупый вопрос, но всё же.
Есть машинка с Debian, на ней установлен Docker CE.
И мой вопрос — можно ли запустить в контейнере Docker Windows приложение (например я хочу попробовать www.passmark.com/products/pt.htm)
EN-форумы утверждают, что нет, но это было до выхода Docker for Windows.
Сейчас же на странице Docker висит красивая диаграмма, утверждающая, что можно запустить любое приложение на любой ОС, но видимо речь о собственных приложениях 🙂
You can run Windows-based containers on Windows Server 2016 and Windows 10. Windows-based containers require a Windows kernel to run, in the same way that Linux-based containers require a Linux kernel to run. You can even run Windows-based containers on a Windows virtual machine running on an macOS or Linux host. Docker Machine is not necessary if you run macOS 10.10.3 Yosemite, Windows Server 2016, or Windows 10.
Нет.
Докер — это не особо большая НАДСТРОЙКА над ядром Линукса.
Он просто удобным способом позволяет изолировать и запускать родные приложения Линукса.
Из неродных вариантов — разве только запуск Линуксовых приложений из под Докера ФриБСД или напротив запуск Фришных приложение из под Докера Линуха — так как эти операционные системы близки.
С Виндовс сие невозможно в принципе.
Тот Докер что устанавливается в Виндовс — тянет за собой полноценный Линукс. И только это делает возможным запуска Линукс приложений в Докере Виндовс.
Обратная процедура также нетривиальна.
Если вам нужен аналог Докера для запуска приложений Виндовс — обратитесь к технологии Windows Container.
Preview: Linux Containers on Windows
Microsoft is getting ready for the next big update for Windows Server (check out today’s complimentary Microsoft blog post ) and some of the new features are very exciting for Docker users. One of the most important enhancements is that Docker can now run Linux containers on Windows (LCOW), using Hyper-V technology.
Running Docker Linux containers on Windows requires a minimal Linux kernel and userland to host the container processes. This is exactly what the LinuxKit toolkit was designed for: creating secure, lean and portable Linux subsystems that can provide Linux container functionality as a component of a container platform.
We’ve been busy prototyping LinuxKit support for Docker Linux containers on Windows and have a working preview for you to try. This is still a work in progress, and requires either the recently announced “Windows Server Insider” or Windows 10 Insider builds.
UPDATE: LCOW support is available in Windows 10 Fall Creators Update and in Windows Server 1709. The simplest way to try it out on Windows 10 is to install the edge variant of Docker for Windows (details). On Windows Server 1709, install EE preview.
Running Docker Linux Containers on Windows with LinuxKit
The instructions below have been tested on Windows 10 and Windows Server Insider builds 16278 and 16281.
Be sure to install Docker for Windows (Windows 10) or Docker Enterprise Edition (Windows Server Insider) before starting.
Setup Docker and LinuxKit
A preview build of LinuxKit is available by simply running the following commands in PowerShell (with Administrator rights):
Now get a master branch build of the Docker daemon that contains preview support for Linux containers on Windows:
Start a new Docker daemon listening on a separate pipe and using a separate storage location from the default install:
Try it
Run a Linux container:
Docker just launched a minimal VM running a LinuxKit instance hosting the Linux container!
Since this is an early preview there are some limitations, but basic Docker operations like pull and run work.
Looking ahead
Both Windows Server Insider builds and Docker support for Linux containers on Windows are in early preview mode. When GA, Docker Linux containers on Windows will improve the Docker Linux container experience for both Windows developers and server administrators. Developers will be able to more easily build and test mixed Windows/Linux Docker applications by running containers for both platforms side-by-side on the same system.
And IT-admins that prefer Windows will soon be able to easily run (mostly) Linux-only software like HAProxy and Redis on Windows systems by way of Docker Linux containers on Windows. For example, Docker Linux containers on Windows will make setting up Docker Enterprise Edition and Universal Control Plane (which relies on some Linux-only components) on Windows Server much simpler.
We hope this LinuxKit-based walkthrough will set you up to start experimenting. Feedback is always welcome! For general help and getting started with Insider builds use the Windows Feedback Hub (Windows 10), or the Windows Server Insiders Tech Community . For issues with LinuxKit and Docker support for Linux containers on Windows use the Docker for Windows issue tracker on GitHub . And let us know on Twitter if you build something cool!