且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows容器可以托管在Linux上吗?

更新时间:2023-12-06 14:26:58

更新3:06.2019 一些评论说答案不清楚,我将尽力澄清.

Update3: 06.2019 Some of the comments says that the answer is not clear, I'll try to clarify.

TL; DR:

问: Windows容器可以在Linux上运行吗?

Q: Can Windows containers run on Linux?

A: 否.他们不能. 容器正在使用底层的操作系统资源和驱动程序,因此Windows容器只能在Windows上运行,Linux容器只能在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:但是Windows的Docker呢?还是其他基于VM的解决方案?

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

A: Windows的Docker允许您在 Windows 上模拟正在运行的 Linux 容器. strong>,但是在后台创建了Linux VM,因此 Linux容器仍在Linux上运行,而Windows容器仍在Windows上运行.

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.

奖金:阅读这篇关于跑步的很好文章 Windows上的Linux docker容器.

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

Q:那么,如果我想在容器中运行,应该使用.Net Framework 462应用程序怎么办?

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

A:这要视情况而定.以下是一些建议:

A: It depends. Following several recommendations:

  • 如果可能的话-移至.Net Core.由于.Net Core为.Net Framework和.Net Framework 4.8的大多数主要功能提供了支持,因此
  • 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.

(不建议使用)在某些情况下,您可以运行Windows容器. Windows容器变得越来越成熟,并且在诸如Kubernetes之类的平台中提供了更好的支持.但是,要能够运行.Net Framework代码,您仍然需要在"Server Core"的基本映像上运行,该映像大约占1.4 GB.在极少数情况下,您可以将代码迁移到.Net Core,但仍可以在Windows Nano服务器上运行,图像大小为95 MB.

(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.

还保留了历史记录的旧更新

Update2:08.2018 如果您使用的是适用于Windows的Docker,则现在可以同时同时运行Windows和Linux容器:

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/

奖金::与问题没有直接关系,但是您现在不仅可以运行linux容器本身,还可以运行诸如kubernetes之类的编排器:

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/

2018年更新:

Updated at 2018:

最初的答案通常是正确的,但是几个月前,码头工人添加了官方github存储库).

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

来自此帖子:

用于Windows的Docker是否已经运行Linux容器?这是正确的. 适用于Windows的Docker可以运行Linux或Windows容器,并提供支持 通过Hyper-V Moby Linux VM用于Linux容器(自Docker开始, Windows 17.10,此VM基于LinuxKit).

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).

使用LCOW运行Linux容器的设置比简单得多 以前的架构,其中Hyper-V Linux VM运行Linux Docker 守护程序以及所有容器.使用LCOW,Docker守护程序 作为Windows进程运行(与运行Docker Windows时相同) 容器),并且每次启动Linux容器Docker时 启动运行Linux和VM的最小Hyper-V虚拟机管理程序 内核,runc和运行在顶部的容器进程.

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.

因为只有一个Docker守护程序,并且因为该守护程序现在 在Windows上运行,很快将可以在Windows和Linux上运行 在同一网络名称空间中并排放置Docker容器.这 将解锁许多激动人心的开发和生产场景, Windows上的Docker用户.

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:

如@PanagiotisKanavos的评论中所述,容器不用于虚拟化,并且它们正在使用主机的资源.因此,目前Windows容器无法在Linux计算机上按原样运行.

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.

但是-您可以使用VM来实现-因为它可以在Windows上使用.您可以在Linux主机上安装Windows VM,这将允许运行Windows容器.

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.

有了它,恕我直言,在PROD环境中以这种方式运行它并不是***的主意.

With it, IMHO run it this way on PROD environment will not be the best idea.

此外,此答案提供了更多详细信息

Also, this answer provides more details.