简体   繁体   English

在 Windows 10 Pro 上创建 .NET Core 3.1 应用程序的 Docker 映像并将其拉到 ZAEA23489CE3AA9B6406EBB201

[英]Create Docker Image of .NET Core 3.1 app on Windows 10 Pro and pull it to Windows Server 2016

I have successfully created Docker images that contain .NET Core 3.1 projects and am running them in Windows Containers on my local Windows 10 Pro machine.我已经成功创建了包含 .NET Core 3.1 项目的 Docker 映像,并在我的本地 Windows 容器中运行它们。 I am using Windows Containers, not Linux.我使用的是 Windows 容器,而不是 Linux。

I want to be able to pull them to a Windows 2016 Server machine (not a VM).我希望能够将它们拉到 Windows 2016 服务器机器(不是 VM)。 I have Docker EE installed on the Windows 2016 Server and it is running.我在 Windows 2016 服务器上安装了 Docker EE,它正在运行。 docker version reports Version 20.10.0. docker 版本报告版本 20.10.0。

According to the following, there are not any supported .NET Core images available for Windows Server 2016. no matching manifest for windows/amd64 Server 2016根据以下内容,没有任何受支持的 .NET Core 映像可用于 Windows Server 2016。 没有适用于 windows/amd64 Server 2016 的匹配清单

If that is true, am I trying to do something that is impossible?如果这是真的,我是否正在尝试做一些不可能的事情? Or simply not supported?还是根本不支持?

I am new at this, but from what I understand .NET Core apps require nanoserver 1809 or higher to be installed in the host.我是新手,但据我了解 .NET 核心应用程序需要在主机中安装 nanoserver 1809 或更高版本。 If that is incorrect, let me know...如果这不正确,请告诉我...

NOTE: I have successfully pulled this to the Windows 2016 Server:注意:我已成功将其拉到 Windows 2016 服务器:

docker pull mcr.microsoft.com/windows/nanoserver:sac2016

But from what I read here, https://github.com/dotnet/dotnet-docker/issues/1041 , .NET Core 3.x is no longer supported on that base.但从我在这里读到的内容来看,该基础不再支持https://github.com/dotnet/dotnet-docker/issues/1041、.NET Core 3.x。

ISSUE 1问题 1

When I run the following on the Windows 2016 Server, I get the error "no matching manifest for windows/amd64 10.0.14393 in the manifest list entries".当我在 Windows 2016 服务器上运行以下命令时,我收到错误“清单列表条目中没有 windows/amd64 10.0.14393 的匹配清单”。

docker pull mcr.microsoft.com/windows/nanoserver:1809

According to this page, I should be able to pull that: https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-server根据此页面,我应该能够得出: https://docs.microsoft.com/en-us/virtualization/windowscontainers/deploy-containers/deploy-containers-on-server

ISSUE 2问题 2

From what I read it looks like I will need to create my images or at least run them in containers in "hyperv" isolation mode.从我读到的内容看来,我需要创建我的图像,或者至少在容器中以“hyperv”隔离模式运行它们。 Correct?正确的? Or can the docker host itself run a different version of the OS (like nanoserver 1809 or whatever)?还是 docker 主机本身可以运行不同版本的操作系统(如 nanoserver 1809 或其他)? I'm using Visual Studio to build all of this locally and am also using docker-compose where I can specify the isolation mode in the yml file.我正在使用 Visual Studio 在本地构建所有这些,并且还使用 docker-compose 可以在 yml 文件中指定隔离模式。 But I don't know how to do that when I publish my images to my Docker Hub through VS.NET.但是当我通过 VS.NET 将图像发布到我的 Docker 集线器时,我不知道该怎么做。 My images publish successfully, but then when I try to use docker pull to bring them down to the Windows 2016 Server I get this error:我的图像发布成功,但是当我尝试使用 docker pull 将它们降低到 Windows 2016 服务器时,我收到此错误:

a Windows version 10.0.19042-based image is incompatible with a 10.0.14393 host

ISSUE 3问题 3

Related to the above error, I guess I need to include an older Windows base version in my image?与上述错误相关,我想我需要在我的图像中包含一个较旧的 Windows 基本版本? I have added the following to my dockerfile:我在 dockerfile 中添加了以下内容:

FROM mcr.microsoft.com/windows/nanoserver:1809

But it didn't seem to do anything.但它似乎没有做任何事情。 When I run the project in VS.NET, I see this when I inspect the container:当我在 VS.NET 中运行项目时,我在检查容器时看到了这一点:

OsVersion: 10.3.19042.867

My goal for a proof of concept is simply to:我的概念证明目标很简单:

  1. Create an image of a .NET Core 3.1 web api project on my Windows 10 Pro laptop在我的 ZAEA23489CE3AAA9B6406EBB28E0 笔记本电脑上创建 .NET Core 3.1 web api 项目的映像
  2. Pull it to a Windows 2016 Server and run it in a Docker Container.将其拉到 Windows 2016 服务器并在 Docker 容器中运行。

#1 all works on my laptop. #1 都适用于我的笔记本电脑。 Getting #2 accomplished is where I'm really confused.完成#2是我真正感到困惑的地方。

Thanks, Brent谢谢,布伦特

UPDATE更新

Below are the Dockerfile and commands I use to build the image, run it in a container and inspect it.下面是 Dockerfile 和我用来构建映像、在容器中运行并检查它的命令。 NOTE that with this Dockerfile, in the interactive command prompt I do now see:请注意,使用此 Dockerfile,我现在在交互式命令提示符中看到:

  • the correct OS ver: 10.0.14393正确的操作系统版本:10.0.14393
  • the file system does contain my.Net solution, project and my source code.文件系统确实包含 my.Net 解决方案、项目和我的源代码。

I've just taken what MattT provided and added it to the beginning of the Dockerfile that VS.NET generated when I added DockerSupport.我刚刚采用了 MattT 提供的内容并将其添加到 VS.NET 在添加 DockerSupport 时生成的 Dockerfile 的开头。 I know I have goofed my Dockerfile up because it doesn't build / publish or run my webapi project (as it did prior to adding the new commands).我知道我搞砸了我的 Dockerfile,因为它没有构建/发布或运行我的 webapi 项目(就像在添加新命令之前所做的那样)。 I assume it has something to do with my FROM statements.我认为这与我的 FROM 语句有关。 I've read so much, but don't yet understand how layering works, among other things.我读了很多,但还不明白分层是如何工作的,等等。

# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS baseOS
RUN powershell -Command [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12; $ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -UseBasicParsing -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; ./dotnet-install.ps1 -InstallDir '/Program Files/dotnet' -Channel 3.1 -Runtime dotnet; Remove-Item -Force dotnet-install.ps1 && setx /M PATH "%PATH%;C:\Program Files\dotnet"
COPY . .

FROM mcr.microsoft.com/dotnet/aspnet:3.1 AS base

WORKDIR /app
EXPOSE 80
EXPOSE 8001

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
WORKDIR /src
COPY ["WebApi.csproj", "."]

RUN dotnet restore "WebApi.csproj"
COPY . .

WORKDIR "/src/"
RUN dotnet build "WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app/publish

FROM base AS final
#FROM baseOS AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApi.dll"]

docker commands I run:我运行的 docker 命令:

docker build -f "C:\Cabinet\Learning\EssApiProjects\src\Services\WebApi\Dockerfile" --force-rm -t webapi:ltsc2016 --target baseOS "C:\Cabinet\Learning\EssApiProjects\src\Services\WebApi"

docker run --env ASPNETCORE_ENVIRONMENT=Development -p 8001:80 --name webapi_ltsc2016 -it webapi:ltsc2016

docker exec -it webapi_ltsc2016 cmd.exe 

There's a difference between what is supported and what is available.支持的内容和可用的内容之间存在差异。 Running .NET Core in a container on Windows Server 2016 is supported but there is not an available image for it.支持在 Windows Server 2016 上的容器中运行 .NET Core,但没有可用的映像。 You're left to define your own.你可以定义你自己的。

Your options for what Windows container versions can run on a Windows Server 2016 host are limited to only Windows Server 2016 containers.您对于 Windows 容器版本可以在 Windows Server 2016 主机上运行的选项仅限于 Windows Server 2016 容器。 This means you cannot run a nanoserver:1809 container on a Server 2016 host, for example.例如,这意味着您不能在 Server 2016 主机上运行nanoserver:1809容器。 This is illustrated in the Windows container version compatibility matrix :这在Windows 容器版本兼容性矩阵中进行了说明:

在此处输入图像描述

Note that nanoserver:sac2016 has long been out of support so it would not be a recommended base image.请注意, nanoserver:sac2016早已不受支持,因此它不是推荐的基础映像。 There is not any currently supported tag for Nano Server on 2016. Instead, it'd be recommended to use Windows Server Core. Nano Server 2016 目前没有任何支持的标签。相反,建议使用 Windows Server Core。 The servercore:ltsc2016 is your best option for a supported tag. servercore:ltsc2016是受支持标签的最佳选择。

Here's an example of how you would install .NET Core on a Server Core image:以下是如何在服务器核心映像上安装 .NET 核心的示例:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2016
RUN powershell -Command `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
        Invoke-WebRequest `
            -UseBasicParsing `
            -Uri https://dot.net/v1/dotnet-install.ps1 `
            -OutFile dotnet-install.ps1; `
        ./dotnet-install.ps1 `
            -InstallDir '/Program Files/dotnet' `
            -Channel 3.1 `
            -Runtime aspnetcore; `
        Remove-Item -Force dotnet-install.ps1 `
    && setx /M PATH "%PATH%;C:\Program Files\dotnet"

Further resources:更多资源:

UPDATE更新

Here's an example of how this would be defined using a Dockerfile generated by Visual Studio:下面是如何使用 Visual Studio 生成的 Dockerfile 定义的示例:

# escape=`
FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS base

# Install ASP.NET Core 3.1
RUN powershell -Command `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
        Invoke-WebRequest `
            -UseBasicParsing `
            -Uri https://dot.net/v1/dotnet-install.ps1 `
            -OutFile dotnet-install.ps1; `
        ./dotnet-install.ps1 `
            -InstallDir '/Program Files/dotnet' `
            -Channel 3.1 `
            -Runtime aspnetcore; `
        Remove-Item -Force dotnet-install.ps1 `
    && setx /M PATH "%PATH%;C:\Program Files\dotnet"

WORKDIR /app
EXPOSE 80
EXPOSE 8001

FROM mcr.microsoft.com/windows/servercore:ltsc2016 AS build

# Install .NET Core 3.1 SDK
RUN powershell -Command `
        $ErrorActionPreference = 'Stop'; `
        $ProgressPreference = 'SilentlyContinue'; `
        [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
        Invoke-WebRequest `
            -UseBasicParsing `
            -Uri https://dot.net/v1/dotnet-install.ps1 `
            -OutFile dotnet-install.ps1; `
        ./dotnet-install.ps1 `
            -InstallDir '/Program Files/dotnet' `
            -Channel 3.1; `
        Remove-Item -Force dotnet-install.ps1 `
    && setx /M PATH "%PATH%;C:\Program Files\dotnet"

WORKDIR /src
COPY ["WebApi.csproj", "."]

RUN dotnet restore "WebApi.csproj"
COPY . .

WORKDIR "/src/"
RUN dotnet build "WebApi.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WebApi.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApi.dll"]

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

相关问题 如何在 windows server 2016 中成功拉取 windows nano server docker 镜像? - How to pull windows nano server docker image successfully in windows server 2016? Docker Image for Windows server 2016 with framework .NET 5.0 - Docker Image for Windows server 2016 with framework .NET 5.0 无法在 Windows 上拉取 docker 映像 10 - Unable to pull docker image on Windows 10 如何在Windows 10 Pro上构建Windows Server Core? - How to build windows server core on Windows 10 Pro? 在 WINDOWS 2016 服务器中拉取 Docker 图像时出错(Windows 的 docker) - ERROR IN PULLING DOCKER IMAGE IN WINDOWS 2016 SERVER (docker for windows) 艾泽拉斯核心 Docker 安装在 Windows 10: Pro 上的问题 - Issue with Azeroth Core Docker install on Windows 10: Pro ASP.NET Core 3.1 Angular Web App builds and runs on Windows but fails on Mac OSX and in Docker - ASP.NET Core 3.1 Angular Web App builds and runs on Windows but fails on Mac OSX and in Docker Windows Server 2016 Docker镜像支持SQL Server? - Windows Server 2016 Docker image support for SQL Server? 我可以在 Windows 2019 服务器上创建 Windows 2016 容器映像吗? - Can I create a Windows 2016 container image on a Windows 2019 server? 在Windows Server 2016上安装Docker - Installing Docker On Windows Server 2016
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM