简体   繁体   English

GenerateRuntimeConfigurationFiles任务意外失败

[英]GenerateRuntimeConfigurationFiles task failed unexpectedly

I'm getting inconsistent errors when building my docker image. 构建我的docker镜像时,我遇到了不一致的错误。 This fails approximately 1 out of 3 times, if i keep running docker build. 如果我继续运行docker build,这大约会失败3次。

The full error is: 完整的错误是:

/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018: The "GenerateRuntimeConfigurationFiles" task failed unexpectedly. [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018: System.IO.IOException: The process cannot access the file '/app/MyProject.Api/bin/Release/netcoreapp2.1/MyProject.Api.runtimeconfig.json' because it is being used by another process. [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at System.IO.FileStream.Init(FileMode mode, FileShare share) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at System.IO.File.Create(String path) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateRuntimeConfigurationFiles.WriteToJsonFile(String fileName, Object value) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateRuntimeConfigurationFiles.WriteRuntimeConfig(ProjectContext projectContext) [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateRuntimeConfigurationFiles.ExecuteCore() [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/app/MyProject.Api/MyProject.Api.csproj]
/usr/share/dotnet/sdk/2.1.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(171,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/app/MyProject.Api/MyProject.Api.csproj]
  MyProject.Api -> /app/MyProject.Api/bin/Release/netcoreapp2.1/MyProject.Api.dll
  MyProject.Api -> /app/MyProject.Api/out/
The command '/bin/sh -c ps -ef && dotnet publish --configuration Release --no-restore --framework netcoreapp2.1 --output out' returned a non-zero code: 1

What bothers me is this line The process cannot access the file '/app/MyProject.Api/bin/Release/netcoreapp2.1/MyProject.Api.runtimeconfig.json' because it is being used by another process . 困扰我的是这一行该进程无法访问文件'/app/MyProject.Api/bin/Release/netcoreapp2.1/MyProject.Api.runtimeconfig.json',因为它正被另一个进程使用 [/app/MyProject.Api/MyProject.Api.csproj] [/app/MyProject.Api/MyProject.Api.csproj]

What other process could be locking the file ? 还有哪些进程可以锁定文件?

When the build process doesn't fail this warning shows up every time: 当构建过程没有失败时,每次出现此警告:

/usr/share/dotnet/sdk/2.1.301/Microsoft.Common.CurrentVersion.targets(4560,5): warning MSB3026: Could not copy "/app/MyProject.Api/Keys/public.pem" to "bin/Release/netcoreapp2.1/Keys/public.pem". Beginning retry 1 in 1000ms. The process cannot access the file '/app/MyProject.Api/bin/Release/netcoreapp2.1/Keys/public.pem' because it is being used by another process.  [/app/MyProject.Api/MyProject.Api.csproj]

Which looks like the same issue, but is resolved on it's own, and builds the image, and the public.pem file has been copied correctly. 看起来像是同一个问题,但是它自己解决,并构建映像,并且public.pem文件已被正确复制。

my dockerfile: 我的dockerfile:

FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

COPY . ./

RUN dotnet restore --source https://api.nuget.org/v3/index.json

RUN dotnet publish --configuration Release --no-restore --framework netcoreapp2.1 --output out

FROM microsoft/dotnet:2.1.1-aspnetcore-runtime as runtime
WORKDIR /app

COPY --from=build-env /app/MyProject.Api/out .
ENTRYPOINT ["dotnet", "MyProject.Api.dll"]

and i run docker build like so: docker build --no-cache -t myproject:test -f Dockerfile . 我像这样运行docker build:docker build --no-cache -t myproject:test -f Dockerfile。

the only similar issues i've found posted on github, are consistent failures where this works most of the time, but fails regularly, and i still don't understand why. 我发现在github上发现的唯一类似问题是大多数情况下这种情况一致的失败,但是经常失败,我仍然不明白为什么。

Any help is appreciated. 任何帮助表示赞赏。

You can use fuser [used file] on linux 你可以在linux上使用fuser [used file]

Or lsof [used file] on MacOS 或者在MacOS上使用[used file]

to find the pid of that process. 找到那个过程的pid。

I think some of the commands in the Dockerfile need to be changed. 我认为Dockerfile中的一些命令需要更改。

FROM microsoft/dotnet:2.1-sdk AS build-env
WORKDIR /app

COPY *.csproj ./
RUN dotnet restore

# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:2.1.1-aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyProject.Api.dll"]

References: 参考文献:

  1. https://docs.docker.com/engine/examples/dotnetcore/#prerequisites https://docs.docker.com/engine/examples/dotnetcore/#prerequisites

  2. https://raw.githubusercontent.com/dotnet/dotnet-docker/master/samples/dotnetapp/Dockerfile https://raw.githubusercontent.com/dotnet/dotnet-docker/master/samples/dotnetapp/Dockerfile

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

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