简体   繁体   English

.net 核心 Web 应用程序 docker 映像如何在 Mac OS 上运行?

[英]How can a .net core web app docker image run on Mac OS?

Ok I know I'm being a noob here but I'm trying to get my head around Docker... I've created a simple .net core Web API app that returns some data.好的,我知道我在这里是个菜鸟,但我正在尝试了解 Docker...我已经创建了一个简单的 .net 核心 Web API 应用程序,它返回一些数据。 I did this in Windows, pushed to gitlab, but then I can clone on Mac and runs fine as expected...我在 Windows 中做了这个,推送到 gitlab,但后来我可以在 Mac 上克隆并按预期运行良好......

I then create a Dockerfile that includes..然后我创建一个 Dockerfile,其中包括..

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /app

...

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
WORKDIR /app

As I understand it, does the core sdk include the small nano server windows OS?据我了解,核心 sdk 是否包括小型纳米服务器 Windows 操作系统? Does that mean that when I use docker run on Mac it's actually running the app on Windows - kind of like in a mini VM on the Mac?这是否意味着当我在 Mac 上使用docker run ,它实际上是在 Windows 上运行应用程序 - 有点像在 Mac 上的迷你 VM 中?

If this is correct, how does docker know to use the windows nano server, rather than a linux image for example?如果这是正确的,docker 如何知道使用 windows nano 服务器,而不是例如 linux 映像?

Thanks for any help谢谢你的帮助

Short Answer:简答:

Because .NET Core is cross-platform.因为 .NET Core 是跨平台的。 And docker works on Mac and Windows (theoretically just the way it works on Linux) the image will work just fine on any platform.并且 docker 在 Mac 和 Windows 上工作(理论上只是在 Linux 上的工作方式),该图像在任何平台上都可以正常工作。

mcr.microsoft.com/dotnet/core/sdk:3.1 is platform dependent. mcr.microsoft.com/dotnet/core/sdk:3.1 取决于平台。 Depending on the architecture you choose to run Docker it'll pick up Windows Nano server or Linux template.根据您选择运行 Docker 的架构,它会选择 Windows Nano 服务器或 Linux 模板。

Long Answer:长答案:

Docker is not a VM technology. Docker 不是虚拟机技术。 It's a Linux feature that provides you an isolated environment.它是一个 Linux 功能,可为您提供隔离环境。 Docker is not possible on Windows and Mac. Docker 在 Windows 和 Mac 上是不可能的。 Docker uses Linux features and plugs in an application (and it's related dependencies) in the Linux environment and creates an illusion of resources (network, RAM, disk, software frameworks) needed for running the application. Docker 使用 Linux 功能并在 Linux 环境中插入应用程序(及其相关依赖项),并创建运行应用程序所需的资源(网络、RAM、磁盘、软件框架)的错觉。

On windows and Mac.在 Windows 和 Mac 上。 Docker installs a Linux VM. Docker 安装 Linux VM。 And runs the Docker infra inside the VM.并在 VM 内运行 Docker 基础设施。

commands like docker info will give more details.诸如docker info类的命令将提供更多详细信息。 This picture below shows that it's running on Linux.下图显示它在 Linux 上运行。

在此处输入图片说明

Switching to Windows docker will give a different output for docker info command.切换到 Windows docker 将为docker info命令提供不同的输出。

在此处输入图片说明

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

相关问题 无法为 .NET 核心创建 docker 映像 - Can't create docker image for .NET Core 如何使用 .NET Core 3.1.0 中的 ACL 在 Mac OS 上管理文件夹权限 - How to manage folders permissions on Mac OS with ACL in .NET Core 3.1.0 .Net Core 3.1 with SoapCore - 如何在 Docker 中运行它? - .Net Core 3.1 with SoapCore - how to run it in Docker? 无法在 Mac 上的命令行中运行 .NET Core 应用程序 - Cannot run .NET Core app in command line on Mac 在没有核心运行时的情况下在Apache上运行.Net Core Web App - Run .Net Core Web App on Apache without Core Runtime 无法运行.NET Core默认应用 - Can't run the .NET core default app 既然 .NET Framework 的那一部分可以在 Mac 和 Linux 上运行,我们如何知道 .NET 应用程序是否会在 Windows 之外运行? - Now that part of the .NET Framework runs on Mac and Linux, how can we know if a .NET app will run outside of Windows? 如何将 .NET [框架] web 应用程序部署到 docker - How to deploy .NET [framework] web app to docker 在 Mac OS 上使用 React 构建 ASP.NET 核心应用程序时出现“命令“npm install”退出并显示代码 1”错误? - 'The command "npm install" exited with code 1' error when building the ASP.NET Core app with React on mac OS? 针对 .net 核心 Web 应用程序运行 Selenium 测试 - Run Selenium tests against .net core web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM