简体   繁体   English

在Docker中创建新的ASP.NET Core MVC应用程序时,NuGet软件包的还原非常缓慢

[英]NuGet package restore extremely slow when creating new ASP.NET Core MVC app in Docker

For troubleshooting an existing ASP.NET Core 2.1 MVC application, I want to host a simple hello world ASP.NET Core MVC application on the same server using Docker. 为了对现有的ASP.NET Core 2.1 MVC应用程序进行故障排除,我想使用Docker在同一服务器上托管一个简单的hello world ASP.NET Core MVC应用程序。 So I created a small Dockerfile: 因此,我创建了一个小的Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS sdk-image
run dotnet new mvc
RUN dotnet publish -c Debug -o /publish

FROM mcr.microsoft.com/dotnet/core/aspnet:2.1 AS runtime-image
COPY --from=sdk-image /publish .
ENV ASPNETCORE_URLS=http://0.0.0.0:5000
ENV ASPNETCORE_ENVIRONMENT=Development
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

But the container hangs on restoring NuGet packages: 但是容器挂在恢复NuGet包上:

Step 2/9 : RUN dotnet new mvc
 ---> Running in 54b50f10572b
Getting ready...
The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore-template-3pn-210 for details.

Processing post-creation actions...
Running 'dotnet restore' on /WebApplication1.csproj...

Those restore doesn't get finished even after minutes of waiting. 即使经过几分钟的等待,这些还原仍无法完成。 The default template of ASP.NET Core MVC contains only a few packages. ASP.NET Core MVC的默认模板仅包含一些软件包。

It was noticeable that dotnet uses CPU ressources continuily and another project that refers multiple NuGet ressources got restored after 10 seconds. 值得注意的是, dotnet连续使用CPU资源,另一个引用多个NuGet资源的项目在10秒后得到恢复。 So it's not a network issue and it indicates that NuGet is doing something. 因此,这不是网络问题,它表明NuGet在做什么。

I found this question where a large project folder seems slowing down NuGet because it scans the entire folder. 我发现了一个问题 ,其中大型项目文件夹似乎会减慢NuGet的速度,因为它会扫描整个文件夹。 This seems applying to me too, since my quick test was done in the root file system of the container. 这似乎也适用于我,因为我的快速测试是在容器的根文件系统中完成的。 So the fix was to simply create a sub-directory for the project: 因此,解决方法是为项目创建一个子目录:

FROM mcr.microsoft.com/dotnet/core/sdk:2.1 AS sdk-image
RUN mkdir test
WORKDIR /test
RUN dotnet new mvc

Now NuGet is finished with package restoring after a few seconds. 现在,NuGet在几秒钟后完成了程序包还原。 The lesson learned is: Always use a clean sub directory, even when it's a quick & dirty test container where it (theoretically) shouldnt matter... 吸取的教训是:始终使用一个干净的子目录,即使它是一个快速且肮脏的测试容器,从理论上讲也不重要...

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM