Azure 应用服务上的 ASP.NET Core 2.1 Docker 容器的正确 Windows 基础映像是什么



我想创建一个可以托管在适用于 Windows 的 Azure 应用服务上的 Docker 映像。我的应用程序基于 ASP.NET Core 2.1,根据 .NET 映像映像的官方列表,我应该能够简单地使用microsoft/dotnet:2.1-aspnetcore-runtime.

我可以在Windows机器上成功构建Dockerfile,并且能够在那里运行它而不会出现问题。但在将其上传到 Docker 中心并将其设置为应用服务的 Docker 映像后,我收到以下错误消息:

无法在 Windows 容器中运行此操作系统/版本。 支持的最大操作系统版本为 10.0.14393.9999。

根据 Azure 应用服务文档,它应支持将microsoft/dotnet:2.1-aspnetcore-runtime作为预安装的父映像之一。

检查我的 Docker 映像时,我发现使用的映像对于 Azure 应用服务来说似乎太新了:

"Architecture": "amd64",
"Os": "windows",
"OsVersion": "10.0.17134.285" <-- too new

经过一些研究,我在此博客文章中发现,Windows 上的 Azure 应用服务可能只接受microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016图像。所以我试图用这些重建 Docker 映像。

这一次,应用服务接受了映像,但无法启动它,并引发以下日志:

02/10/2018 14:15:09.437 ERROR - Site: rothiewindockerdemo - Image pull reported error. Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016. failed to register layer: re-exec error: exit status 1: output: remove \?C:DockerDatawindowsfilter93b716197958ceb58006ff3d978fcb3202f7866d00d6d8d69513cf0478a17a7fUtilityVMFilesWindowsservicingPackagesMicrosoft-UtilityVM-Core-Package~31bf3856ad364e35~amd64~~10.0.14393.0.cat: The process cannot access the file because it is being used by another process.
02/10/2018 14:15:09.437 INFO - Site: rothiewindockerdemo - Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016
Custom Registry: https://index.docker.io
02/10/2018 14:15:09.439 ERROR - Site: rothiewindockerdemo - Pull image completed but it was not found locally. Image: robinmanuelthiel/contosomaintenance-api:latest-windows-sac2016
02/10/2018 14:15:09.441 WARNING - Site: rothiewindockerdemo - Attempt 1 to start container was unsuccessful. Maximum attempts: 3. 
02/10/2018 14:15:09.568 INFO - Site: rothiewindockerdemo - Purging after container failed to start
02/10/2018 14:15:09.582 INFO - Site: rothiewindockerdemo - Purging pending logs after stopping container

那么,Azure 应用服务上 ASP.NET Core 2.1 Docker 容器的正确 Windows Docker 基础映像是什么?

这是我Dockerfile

#######################################################
# Step 1: Build the application in a container        #
#######################################################
# Download the official ASP.NET Core SDK image 
# to build the project while creating the docker image
FROM microsoft/dotnet:2.1-sdk as build
WORKDIR /app
# Restore NuGet packages
COPY *.csproj .
RUN dotnet restore
# Copy the rest of the files over
COPY . .
# Build the application
RUN dotnet publish --output /out/ --configuration Release
#######################################################
# Step 2: Run the build outcome in a container        #
#######################################################
# Download the official ASP.NET Core Runtime image
# to run the compiled application
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
# Open HTTP and HTTPS ports
EXPOSE 80
EXPOSE 443
# Copy the build output from the SDK image
COPY --from=build /out .
# Start the application
ENTRYPOINT ["dotnet", "MyApp.dll"]

问题在于microsoft/dotnet:2.1-aspnetcore-runtime是一个多体系结构基础映像。这意味着 Docker 构建将为本地计算机(您正在构建 docker 映像的计算机(选择最佳体系结构。我假设您的本地计算机是 Windows 10 April 2018 更新(版本 1803 - 其内部版本号 17134.407(。截至目前,我们仅支持基于 Windows Server 2016(版本 1709,内部版本号 14393.XX(的映像。

为了"强制"特定版本,请改用此基本映像:microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016。您可以在 https://hub.docker.com/r/microsoft/dotnet/中检查所有可用的标签

我们将努力在我们的文档中特别指出这一点。

请务必提及,应用服务上的 Windows 容器目前为预览版。

门户上的验证"无法在 Windows 容器中运行此操作系统/版本。显示支持的最大操作系统版本为 10.0.14393.9999",因为我们正在运行使用 Windows Server 2016 RS1 的服务器,并且当前无法运行 RS3+ 的容器。我们目前正在努力启用它们,但目前我们没有可以共享的 ETA。

如果验证通过,则意味着指定的映像应该可以正常工作,并且您看到的问题与映像没有直接关系。这是平台中的一个错误,似乎类似于此处报告的问题:https://github.com/Microsoft/hcsshim/issues/155

我们将继续调查并感谢您报告问题

上面标记为答案的答案不正确。它让你相信使用microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016可以解决你的问题,但它不会。我在 Azure 容器实例上对此进行了测试,但它不起作用。

解决方案是这样的:当您获得 OsVersionNotSupported 时,这意味着映像是使用不受支持的 Windows 版本创建的,并且Microsoft当前不支持任何 SAC 版本(SAC 是半年频道(。所以像 1709 和 1803 这样的版本将不起作用。上面的"解决方案"也不起作用,因为它使用了SAC2016标签。

对于您可以在 docker 文件中使用的所有标签,请转到此处:https://github.com/dotnet/dotnet-docker/blob/master/TAGS.md

您需要转到 https://learn.microsoft.com/en-us/azure/container-instances/container-instances-troubleshooting 并阅读"不支持映像的操作系统版本"部分。它明确指出您需要"...始终部署基于 Windows Server 2016 (LTSC( 的映像..."。

最新更新