Azure 应用服务上 ASP.NET Core 2.1 Docker 容器的正确 Windows 基础映像是什么 [英] What's the correct Windows Base Image for ASP.NET Core 2.1 Docker Containers on Azure App Services

查看:15
本文介绍了Azure 应用服务上 ASP.NET Core 2.1 Docker 容器的正确 Windows 基础映像是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create a Docker Image that can be hosted on Azure App Services for Windows. My application is based on ASP.NET Core 2.1 and according to the official list of .NET images images, I should be able to simply use microsoft/dotnet:2.1-aspnetcore-runtime.

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

I can build the Dockerfile on a Windows machine successfully and was able to run it there without issues. But after uploading it to Docker Hub and setting it as the App Service's Docker Image, I get the following error message:

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

Cannot run this Operating System/Version in Windows Containers. Maximum supported OS version is 10.0.14393.9999.

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

According to the Azure App Services Documentation, it should support the microsoft/dotnet:2.1-aspnetcore-runtime as one of the pre-installed parent images.

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

When inspecting my Docker Image, I found, that the used image seems to be too new for Azure App Services:

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

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

After some research, I found in this blog post, that Azure App Services on Windows might only accept microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016 image. So I tried to rebuild the Docker Image with these.

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

This time, the App Service accepted the image, but was unable to start it, throwing the following logs:

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 Update(版本 1803 - 其内部版本号为 17134.407).截至目前,我们仅支持基于 Windows Server 2016(版本 1709,内部版本号 14393.XX)的映像.

The issue lies in the fact that microsoft/dotnet:2.1-aspnetcore-runtime is a multi-architecture base image. This means that Docker build will pick the best architecture for your local machine (the machine where you are building your docker image). I assume that your local machine is Windows 10 April 2018 Update (Version 1803 - Whose build number 17134.407). As of now, we only support images based off of Windows Server 2016 (Version 1709, up to build number 14393.XX).

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

In order to "force" a specific version, please use this base image instead: microsoft/dotnet:2.1-aspnetcore-runtime-nanoserver-sac2016. You can check all the available tags in https://hub.docker.com/r/microsoft/dotnet/

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

We will work on calling this out specifically in our documentation.

这篇关于Azure 应用服务上 ASP.NET Core 2.1 Docker 容器的正确 Windows 基础映像是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆