繁体   English   中英

In Docker Desktop for windows 10 with WSL2, where does docker containers live & how Linux containers can run a java app, but not windows nanoserver?

[英]In Docker Desktop for windows 10 with WSL2, where does docker containers live & how Linux containers can run a java app, but not windows nanoserver?

I have Windows 10 Enterprise Version and I have installed Docker Desktop, enabled WSL2 backend, and downloaded and installed the Linux kernel update package.

我正在学习 Docker,我对 Docker 如何在幕后工作有一些疑问。

  • 我用 WSL2 在 windows 上绘制了 Docker 的基本架构图,这样对吗?
  • 每当我们创建一个新的 Linux 容器时,它是在 WSL2 提供的同一个轻量级实用程序 VM 中创建的吗?
  • 如果我们创建一个 windows 容器,它会在 windows 操作系统上创建吗?
  • 这些容器可以在需要时访问 windows 和 Linux 内核吗? 就像在Linux container中运行 java 应用程序时一样,它需要 windows Z50484C19F1AFDAF39D2Z1A0,对吗?

在此处输入图像描述

  1. 那么,默认情况下 docker 运行 Linux 容器,我们什么时候需要 windows 容器? I can containerize a java application by using openjdk:8, but I am not able to pull windows nanoserver image when I run Linux containers, it works only when I switch to Windows Containers. 这里发生了什么? 这是否意味着 openjdk:8 图像是 Linux 图像(我不知道怎么说),而 windows nanoserver 图像是 windows 图像?
  2. Linux 容器如何运行我的 java 应用程序? 它必须需要 windows kernel,对吧?
  3. If the docker containers reside within the lightweight utility VM created by WSL2, can it access both the Linux kernel that it ships with and the Windows Kernel?

我有默认的Linux container模式,我尝试了这两个命令。

  • docker 运行 --platform=linux -d ubuntu /bin/sh -c "虽然是真的;回显你好世界;睡眠 1;完成"
  • docker 拉 mcr.microsoft.com/windows/nanoserver:1903

第一个适用于第二个我收到以下错误。

1903: Pulling from windows/nanoserver no matching manifest for Linux/amd64 in the manifest list entries

但是当我切换到windows containers时,它可以工作。

  1. 那么我在 openjdk:8 图像上的 java 应用程序和 windows nanoserver 之间有什么区别?
  2. 这些不需要 windows kernel 运行吗?
  3. 那么 java 是如何在 Linux 容器上运行的呢?

编辑:-需要对此进行更多说明-从评论部分复制问题。

  • 还有一件事,容器不会在 WSL2 中同时访问 windows 和 Linux 内核,对吧? 毕竟它们只是操作系统中的孤立空间,所以它们可以在 windows 或 Linux 中吗? 如果我错了,请纠正我。 The Linux images are built in such a way that it has everything to run my java and as java is a cross platform language so it can run on Linux kernel, is this the concept?

  • 关于我在这里制作的架构图——容器(操作系统中带有应用程序文件的隔离进程),如果是 Linux 容器,它们(多个容器)都运行在同一个 WSL2 VM 上,对吧?

首先,好问题。

我希望我能尽可能地回答它。

那么,默认情况下 docker 运行 Linux 容器,我们什么时候需要 windows 容器?

不需要windows 容器。 您应该始终考虑您的应用程序需要什么。 例如,如果您正在使用 java 应用程序,您将提取 java 映像而不是整个主机操作系统。 我唯一一次提取 windows 映像是在我将只能在 windows 上运行的 ASP.NET 应用程序 docker 化时。

Linux 容器如何运行我的 java 应用程序? 它必须需要 windows kernel,对吧?

在 docker 的上下文中:

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.

if the docker containers reside within the lightweight utility VM created by WSL2, can it access both the Linux kernel that it ships with and the Windows Kernel?

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

那么我在 openjdk:8 图像上的 java 应用程序和 windows nanoserver 之间有什么区别?

openJdk 镜像和 windows nano 服务器核心的区别是他们使用的基础镜像。 openJdk 可能使用一些非常裸露的 unix 操作系统作为基础,而 nanoserver 是一个完整的操作系统,即 windows。

这些不需要 windows kernel 运行吗? openjdk 映像不需要 windows 即可运行,因为它是从 linux 构建的。 windows 的 Docker 将使用 WsL 运行。 nanoserver 只能在 windows 上运行(因为 windows 图像只能在 Windows 上运行)。

那么 java 是如何在 Linux 容器上运行的呢? 我理解这个问题是“openjdk 映像如何在 linux 和 windows 上运行?”

如果是这样,因为它使用 linux 操作系统作为其基础映像,它可以默认在 linux 上运行。 但是因为存在 WsL2,所以创建了一个 VM,并在 windows 中模拟了一个 linux OS。 这就是为什么我们可以在 Docker 上为 Z0F4137ED1502B5045DZ6083C 运行 windows 图像和 linux 图像的原因

我希望这会有所帮助,这里有一些问题的额外提示供您考虑。

  1. 当图像与操作系统类型相同时,图像将始终表现最佳。 这是因为 docker 会利用宿主机的资源,当宿主机和容器是同一个操作系统时,性能会更好。
  2. 使用最适合目的的图像。 不要使用整个操作系统映像来运行 java 应用程序。 而是使用 java 图像。 这适用于广泛的框架和语言。

阅读文章 如果您想阅读更多内容,这是信用文章。

图表不太正确。 Windows Kernel 和托管 WSL2 KVM 的轻量级 VM 都位于 Hyper-V 管理程序之上。 换句话说,WSL2 利用了 Hyper-V。 (另一种选择是仅使用 Hyper-V,但使用 WSL2 更加无缝。)WSL2 使用 docker-desktop 作为主要引导虚拟机,使用 docker-desktop-data 存储图像和容器数据。 9p 网络协议用于无缝的主机到访客和访客到主机的文件访问:

https://wiki.qemu.org/File:9pfs_topology.png

This way, docker commands can be run from both Windows and from within a distro installed under WSL2 such as Ubuntu etc. In both cases, containers run under Linux. 这种架构的基本原理是 Linux Docker 不能安装在 Hyper-V VM 上,也不能安装在 WSL2 Linux 内。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM