首页 > 解决方案 > Azure 应用服务上 ASP.NET Core 2.1 Docker 容器的正确 Windows 基础映像是什么

问题描述

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

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

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

根据Azure App Services Documentation,它应该支持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 Image。

这一次,App Service 接受了镜像,但无法启动它,抛出以下日志:

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:\DockerData\windowsfilter\93b716197958ceb58006ff3d978fcb3202f7866d00d6d8d69513cf0478a17a7f\UtilityVM\Files\Windows\servicing\Packages\Microsoft-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"]

标签: windowsazuredockerasp.net-coreazure-web-app-service

解决方案


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

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

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


推荐阅读