使用 .NET 容器时定位的操作系统What OS to target with .NET containers

由于 Docker 支持多种操作系统,且鉴于 .NET Framework 和 .NET Core 之间的差异,应根据所使用的框架,面向特定操作系统和特定版本。Given the diversity of operating systems supported by Docker and the differences between .NET Framework and .NET Core, you should target a specific OS and specific versions depending on the framework you are using.

对于 Windows,可使用 Windows Server Core 或 Windows Nano Server。For Windows, you can use Windows Server Core or Windows Nano Server. 这两种 Windows 版本分别提供 .NET Framework 和 .NET Core 各自所需的特征(Windows Server Core 中的 IIS 与 Nano Server 中自承载的 web 服务器,如 Kestrel)。These Windows versions provide different characteristics (IIS in Windows Server Core versus a self-hosted web server like Kestrel in Nano Server) that might be needed by .NET Framework or .NET Core, respectively.

对于 Linux,正式的 .NET Docker 映像(如 Debian)中提供并支持多个发行版本。For Linux, multiple distros are available and supported in official .NET Docker images (like Debian).

图 3-1 显示基于所使用的 .NET framework,可使用的操作系统版本。In Figure 3-1 you can see the possible OS version depending on the .NET framework used.

显示要与哪些 .NET 容器一起使用的操作系统的关系图。

图 3-1。Figure 3-1. 根据 .NET framework 确定要面向的操作系统Operating systems to target depending on versions of the .NET framework

部署旧的 .NET Framework 应用程序时,必须以与旧应用程序和 IIS 兼容但具有更大映像的 Windows Server Core 为目标。When deploying legacy .NET Framework applications you have to target Windows Server Core, compatible with legacy apps and IIS, but it has a larger image. 部署 .NET Core 应用程序时,可以针对已经过云优化、使用 Kestrel、更小且启动速度更快的 Windows Nano Server。When deploying .NET Core applications, you can target Windows Nano Server, which is cloud optimized, uses Kestrel and is smaller and starts faster. 还可以面向 Linux,支持 Debian、Alpine 和其他操作系统。You can also target Linux, supporting Debian, Alpine and others. 也使用 Kestrel、更小且启动速度更快。Also uses Kestrel, is smaller, and starts faster.

如果想使用不同的 Linux 发行版本或要使用 Microsoft 不支持的映像版本,还可以创建自己的 Docker 映像。You can also create your own Docker image in cases where you want to use a different Linux distro or where you want an image with versions not provided by Microsoft. 例如,可以使用 ASP.NET Core 创建一个在传统 .NET Framework 和 Windows Server Core 上运行的映像,但这不是常见的 Docker 方案。For example, you might create an image with ASP.NET Core running on the traditional .NET Framework and Windows Server Core, which is a not-so-common scenario for Docker.

重要

与完整的 Windows 映像相比,使用 Windows Server Core 映像时,你可能会发现缺少某些 DLL。When using Windows Server Core images, you might find that some DLLs are missing, when compared to full Windows images. 可以通过创建自定义 Server Core 映像,在映像构建时添加缺失的文件来解决此问题,如本 GitHub 注释中所述。You might be able to solve this problem by creating a custom Server Core image, adding the missing files at image build time, as mentioned in this GitHub comment.

将映像名称添加到 Dockerfile 文件后,可根据所使用的标记选择操作系统和版本,如下例所示:When you add the image name to your Dockerfile file, you can select the operating system and version depending on the tag you use, as in the following examples:

图像Image 注释Comments
mcr.microsoft.com/dotnet/core/runtime:3.1mcr.microsoft.com/dotnet/core/runtime:3.1 .NET Core 3.1 多体系结构:支持 Linux 和 Windows Nano Server,具体取决于 Docker 主机。.NET Core 3.1 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host.
mcr.microsoft.com/dotnet/core/aspnet:3.1mcr.microsoft.com/dotnet/core/aspnet:3.1 ASP.NET Core 3.1 多体系结构:支持 Linux 和 Windows Nano Server,具体取决于 Docker 主机。ASP.NET Core 3.1 multi-architecture: Supports Linux and Windows Nano Server depending on the Docker host.
ASP.NET Core 的 aspnetcore 映像具有多个优化。The aspnetcore image has a few optimizations for ASP.NET Core.
mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slimmcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim Linux Debian 发行版上的 .NET Core 3.1 仅运行时.NET Core 3.1 runtime-only on Linux Debian distro
mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 Windows Nano Server(Windows Server 版本 1809)上的 .NET Core 3.1 仅运行时.NET Core 3.1 runtime-only on Windows Nano Server (Windows Server version 1809)

其他资源Additional resources