Windows 容器可以托管在 Linux 上吗?
Can Windows containers be hosted on Linux?
是否可以在 Linux 上 运行 Windows 容器?该场景基于用.NET(旧网)编写的应用程序和想要[=37=的Linux用户 ] 这与 Docker 需要提供 net462
写 API 在 localhost
.
我正在使用 Docker Desktop for Windows 的测试版。
如果不能,那么为什么可以 Windows 运行 Linux 容器而不是相反?
由于一段时间过去了,而且这个问题很受欢迎,我想在这里补充一点,解决方法是使用新的 .NET Standard。它允许我将 4.6.2
框架打包到一个新库中。
长话短说:
问: 可以 Windows 容器 运行 在 Linux 上吗?
答: 没有。他们不能。
容器正在使用底层操作系统资源和驱动程序,因此 Windows 容器只能 Windows 运行,Linux 容器可以 运行仅限 Linux。
问: 但是 Docker 对于 Windows 呢?或者其他 VM-based 解决方案?
A: Docker for Windows 允许你模拟 运行ning Linux 容器在 Windows,但在引擎盖下 Linux 虚拟机已创建,因此 Linux 容器仍在 Linux 上 运行,而 Windows 容器仍在 [=141=173=] 上=].
奖励:阅读 this very nice article 关于 运行ning Linux docker 容器 Windows.
问: 那么,如果我想 运行 在容器中,我应该如何处理 .NET Framework 462 应用程序?
A: 视情况而定。考虑以下建议:
如果可能,迁移到 .NET Core。由于 .NET Core 支持 .NET Framework 和 .NET Framework 4.8 的大多数主要功能 will be the last version of .NET framework
如果您无法迁移到 .NET Core - 正如@Sebastian 提到的那样 - 您可以将您的库转换为 .NET Standard,并拥有两个版本的应用程序 - 一个在 .NET Framework 4.6 上.2,还有一个在 .NET Core 上——它并不总是显而易见的。 Visual Studio 很好地支持它(使用 multi-targeting),但某些依赖项可能需要格外小心。
(不太推荐)在某些情况下,您可以 运行 Windows 个容器。 Windows 容器越来越成熟,在 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 等平台上得到更好的支持,图像大小为 95 MB。
也留下旧的更新历史
更新 2:08.2018
如果您正在使用 Docker-for-Windows,您现在可以 运行 Windows 和 Linux 容器同时:Running Docker Windows and Linux Containers Simultaneously
奖励: 与问题没有直接关系,但您现在不仅可以 运行 Linux 容器本身,还可以 Linux 像 Kubernetes 这样的编排器: Kubernetes is Now Available In Docker Desktop Stable Channel
2018 年更新:
原来的答案大体上是正确的,但是几个月前,Docker添加了experimental feature LCOW (official GitHub repository)。
来自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.
原文:
正如@PanagiotisKanavos 在评论中提到的,容器不是用于虚拟化的,它们正在使用主机 的资源。因此,目前 Windows 容器不能在 Linux 机器上 运行 “as-is”。
但是 - 您可以使用 VM 来完成 - 因为它适用于 Windows。您可以在 Linux 主机上安装 Windows VM,这将允许 运行 Windows 个容器。
有了它,恕我直言 运行 在 生产 环境中以这种方式安装它并不是最好的主意。
此外, 提供了更多详细信息。
不,您不能 运行 Windows 容器直接放在 Linux。
但是您可以 运行 Linux Windows。
Windows Server 2016 附带 Ubuntu OS 的基本映像(在 2016 年 9 月 beta 服务包 之后)。这就是您可以 运行 Linux on Windows 而不是其他方式的原因。在这里查看。 Finally, Linux Containers Could Run on Windows with Docker’s LinuxKit
您可以在 OS 个容器 Linux 和 Windows 之间切换,方法是右键单击托盘菜单中的 Docker。
您可以在虚拟机中使用 Windows 容器(来宾 OS 应符合要求 - Windows 10 Pro 或 Windows Server 2016)。
例如你可以在系统里面使用VirtualBox. Just enable Hyper-V→加速度→半虚拟化接口.
之后,如果 Docker 由于错误而无法启动,请使用设置中的“切换到 Windows 容器...”。
不同于虚拟化,容器化使用相同的主机OS。所以建立在Linux上的容器不能运行建立在Windows上,反之亦然。
在 Windows 中,您必须借助虚拟化(使用 Hyper-V)才能拥有与容器的 OS 相同的 OS,然后您应该能够运行一样。
Docker for Windows 是一个类似的应用程序,它基于 Hyper-V 构建,有助于 运行 在 Linux Docker 容器中 Windows。
但据我所知,没有任何东西可以帮助 Linux.
上的 运行 Windows 容器
你可以 运行 SQL Server and .NET Core 在 Linux 上,因此现在在 Linux 个容器中。
参见:Microsoft SQL Server by Microsoft | Docker Hub
另外:.NET Core by Microsoft | Docker Hub
你的问题的直接答案当然是,除非有专门为 Linux 编译的版本,否则不会。
解决方案 1 - 使用 VirtualBox
正如 Muhammad Sahputra 在 this post 中建议的那样,可以 运行 Windows OS 在 VirtualBox 内(使用 VBoxHeadless - 没有图形界面)在 Docker 容器.
内
此外,VM 网络配置中的 NAT 设置可以进行端口转发,使您能够传递进出 Docker 容器的任何流量。从广义上讲,这最终允许您在 Linux 机器上 运行 任何基于 Windows 的服务。
也许这不是 Docker 容器的典型用例,但它绝对是解决问题的有趣方法。
解决方案 2 - 使用 Wine
对于简单且可能更复杂的应用程序,您可以尝试在 docker 容器 中使用 wine。
This Docker Hub page 可能会帮助您实现目标。
我希望 Docker 能尽快发布本机解决方案,就像他们几年前在 Windows 上对 docker-machine 所做的那样。
容器使用 OS 内核。 Windows 容器利用进程来 运行。所以从理论上讲,Windows 容器不能在 Linux.
上 运行
但是,有一些使用 VMstyle 解决方案的变通方法。
我 找到了这个在 Mac 上使用 Vagrant and Packer 的解决方案,因此它也应该适用于 Linux:
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.
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)
虽然 Docker for Windows 完全能够 运行 Linux 容器,但反过来,虽然理论上可行,但由于实际原因无法实现。
最明显的一个是,Docker for Windows 可以 运行 免费 Linux VM,Docker for Linux 会需要 Windows 许可证才能 运行 它在 VM 中。
此外,Linux 是完全可定制的,因此 Docker 为 Windows 使用的 Linux VM 已精简到只有几 MB,仅包含运行 容器所需的最低限度,而可用的最小 Windows 发行版约为 1.5 GB。它可能不是一个不切实际的尺寸,但它比 Windows 对应的 Linux 笨重得多。
虽然有人可以以 Linux 的价格出售 Docker 与 Windows 许可证捆绑在一起并准备 运行 Windows 容器的变体在 Linux 下(我不知道这样的产品是否存在),底线是你无法避免支付 Windows 供应商 lock-in 价格:金钱和存储 space.
我们可以在 Windows 上 运行 Linux 个容器。 Docker for Windows 使用 Hyper-V based Linux-Kit or WSL 2 作为后端来促进 Linux 容器。
如果任何 Linux 发行版具有这种设置,我们可以 运行 Windows 容器。 Docker for Linux 仅支持 Linux 个容器。
是否可以在 Linux 上 运行 Windows 容器?该场景基于用.NET(旧网)编写的应用程序和想要[=37=的Linux用户 ] 这与 Docker 需要提供 net462
写 API 在 localhost
.
我正在使用 Docker Desktop for Windows 的测试版。
如果不能,那么为什么可以 Windows 运行 Linux 容器而不是相反?
由于一段时间过去了,而且这个问题很受欢迎,我想在这里补充一点,解决方法是使用新的 .NET Standard。它允许我将 4.6.2
框架打包到一个新库中。
长话短说:
问: 可以 Windows 容器 运行 在 Linux 上吗?
答: 没有。他们不能。
容器正在使用底层操作系统资源和驱动程序,因此 Windows 容器只能 Windows 运行,Linux 容器可以 运行仅限 Linux。
问: 但是 Docker 对于 Windows 呢?或者其他 VM-based 解决方案?
A: Docker for Windows 允许你模拟 运行ning Linux 容器在 Windows,但在引擎盖下 Linux 虚拟机已创建,因此 Linux 容器仍在 Linux 上 运行,而 Windows 容器仍在 [=141=173=] 上=].
奖励:阅读 this very nice article 关于 运行ning Linux docker 容器 Windows.
问: 那么,如果我想 运行 在容器中,我应该如何处理 .NET Framework 462 应用程序?
A: 视情况而定。考虑以下建议:
如果可能,迁移到 .NET Core。由于 .NET Core 支持 .NET Framework 和 .NET Framework 4.8 的大多数主要功能 will be the last version of .NET framework
如果您无法迁移到 .NET Core - 正如@Sebastian 提到的那样 - 您可以将您的库转换为 .NET Standard,并拥有两个版本的应用程序 - 一个在 .NET Framework 4.6 上.2,还有一个在 .NET Core 上——它并不总是显而易见的。 Visual Studio 很好地支持它(使用 multi-targeting),但某些依赖项可能需要格外小心。
(不太推荐)在某些情况下,您可以 运行 Windows 个容器。 Windows 容器越来越成熟,在 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 等平台上得到更好的支持,图像大小为 95 MB。
也留下旧的更新历史
更新 2:08.2018
如果您正在使用 Docker-for-Windows,您现在可以 运行 Windows 和 Linux 容器同时:Running Docker Windows and Linux Containers Simultaneously
奖励: 与问题没有直接关系,但您现在不仅可以 运行 Linux 容器本身,还可以 Linux 像 Kubernetes 这样的编排器: Kubernetes is Now Available In Docker Desktop Stable Channel
2018 年更新:
原来的答案大体上是正确的,但是几个月前,Docker添加了experimental feature LCOW (official GitHub repository)。
来自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.
原文:
正如@PanagiotisKanavos 在评论中提到的,容器不是用于虚拟化的,它们正在使用主机 的资源。因此,目前 Windows 容器不能在 Linux 机器上 运行 “as-is”。
但是 - 您可以使用 VM 来完成 - 因为它适用于 Windows。您可以在 Linux 主机上安装 Windows VM,这将允许 运行 Windows 个容器。
有了它,恕我直言 运行 在 生产 环境中以这种方式安装它并不是最好的主意。
此外,
不,您不能 运行 Windows 容器直接放在 Linux。
但是您可以 运行 Linux Windows。
Windows Server 2016 附带 Ubuntu OS 的基本映像(在 2016 年 9 月 beta 服务包 之后)。这就是您可以 运行 Linux on Windows 而不是其他方式的原因。在这里查看。 Finally, Linux Containers Could Run on Windows with Docker’s LinuxKit
您可以在 OS 个容器 Linux 和 Windows 之间切换,方法是右键单击托盘菜单中的 Docker。
您可以在虚拟机中使用 Windows 容器(来宾 OS 应符合要求 - Windows 10 Pro 或 Windows Server 2016)。
例如你可以在系统里面使用VirtualBox. Just enable Hyper-V→加速度→半虚拟化接口.
之后,如果 Docker 由于错误而无法启动,请使用设置中的“切换到 Windows 容器...”。
不同于虚拟化,容器化使用相同的主机OS。所以建立在Linux上的容器不能运行建立在Windows上,反之亦然。
在 Windows 中,您必须借助虚拟化(使用 Hyper-V)才能拥有与容器的 OS 相同的 OS,然后您应该能够运行一样。
Docker for Windows 是一个类似的应用程序,它基于 Hyper-V 构建,有助于 运行 在 Linux Docker 容器中 Windows。 但据我所知,没有任何东西可以帮助 Linux.
上的 运行 Windows 容器你可以 运行 SQL Server and .NET Core 在 Linux 上,因此现在在 Linux 个容器中。
参见:Microsoft SQL Server by Microsoft | Docker Hub
另外:.NET Core by Microsoft | Docker Hub
你的问题的直接答案当然是,除非有专门为 Linux 编译的版本,否则不会。
解决方案 1 - 使用 VirtualBox
正如 Muhammad Sahputra 在 this post 中建议的那样,可以 运行 Windows OS 在 VirtualBox 内(使用 VBoxHeadless - 没有图形界面)在 Docker 容器.
内此外,VM 网络配置中的 NAT 设置可以进行端口转发,使您能够传递进出 Docker 容器的任何流量。从广义上讲,这最终允许您在 Linux 机器上 运行 任何基于 Windows 的服务。
也许这不是 Docker 容器的典型用例,但它绝对是解决问题的有趣方法。
解决方案 2 - 使用 Wine
对于简单且可能更复杂的应用程序,您可以尝试在 docker 容器 中使用 wine。
This Docker Hub page 可能会帮助您实现目标。
我希望 Docker 能尽快发布本机解决方案,就像他们几年前在 Windows 上对 docker-machine 所做的那样。
容器使用 OS 内核。 Windows 容器利用进程来 运行。所以从理论上讲,Windows 容器不能在 Linux.
上 运行但是,有一些使用 VMstyle 解决方案的变通方法。
我 找到了这个在 Mac 上使用 Vagrant and Packer 的解决方案,因此它也应该适用于 Linux: 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.
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)
虽然 Docker for Windows 完全能够 运行 Linux 容器,但反过来,虽然理论上可行,但由于实际原因无法实现。
最明显的一个是,Docker for Windows 可以 运行 免费 Linux VM,Docker for Linux 会需要 Windows 许可证才能 运行 它在 VM 中。
此外,Linux 是完全可定制的,因此 Docker 为 Windows 使用的 Linux VM 已精简到只有几 MB,仅包含运行 容器所需的最低限度,而可用的最小 Windows 发行版约为 1.5 GB。它可能不是一个不切实际的尺寸,但它比 Windows 对应的 Linux 笨重得多。
虽然有人可以以 Linux 的价格出售 Docker 与 Windows 许可证捆绑在一起并准备 运行 Windows 容器的变体在 Linux 下(我不知道这样的产品是否存在),底线是你无法避免支付 Windows 供应商 lock-in 价格:金钱和存储 space.
我们可以在 Windows 上 运行 Linux 个容器。 Docker for Windows 使用 Hyper-V based Linux-Kit or WSL 2 作为后端来促进 Linux 容器。
如果任何 Linux 发行版具有这种设置,我们可以 运行 Windows 容器。 Docker for Linux 仅支持 Linux 个容器。