作者:筱杰丶Jevon_879 | 来源:互联网 | 2022-12-03 12:12
我想创建一个可以在Windows的Azure应用服务上托管的Docker映像。我的应用程序基于ASP.NET Core 2.1,根据.NET图像图像的官方列表,我应该可以简单地使用microsoft/dotnet:2.1-aspnetcore-runtime
。
我可以在Windows计算机上成功构建Dockerfile,并且能够在其中运行它而不会出现问题。但是在将其上传到Docker Hub并将其设置为App Service的Docker映像后,我收到以下错误消息:
无法在Windows容器中运行此操作系统/版本。支持的最大操作系统版本是10.0.14393.9999。
根据Azure App Services文档,它应支持microsoft/dotnet:2.1-aspnetcore-runtime
作为预安装的父映像之一。
在检查Docker映像时,我发现对于Azure App Services而言,所使用的映像似乎太新了:
"Architecture": "amd64",
"Os": "windows",
"OsVersion": "10.0.17134.285" <-- too new
经过研究,我在这篇博客文章中发现 Windows上的Azure App Services可能仅接受microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016
图像。所以我试图用这些来重建Docker镜像。
这次,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 App Services上用于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"]
小智..
5
问题在于,这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/中检查所有可用标签
我们将努力在我们的文档中对此进行明确说明。
1> 小智..:
问题在于,这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/中检查所有可用标签
我们将努力在我们的文档中对此进行明确说明。