GenerateRuntimeConfigurationFiles任务意外失败

问题描述 投票:3回答:2

构建我的docker镜像时,我遇到了不一致的错误。如果我继续运行docker build,这大约会失败3次。

完整的错误是:

/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

困扰我的是这一行该进程无法访问文件'/app/MyProject.Api/bin/Release/netcoreapp2.1/MyProject.Api.runtimeconfig.json',因为它正被另一个进程使用。 [/app/MyProject.Api/MyProject.Api.csproj]

还有哪些进程可以锁定文件?

当构建过程没有失败时,每次出现此警告:

/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]

看起来像是同一个问题,但是它自己解决,并构建映像,并且public.pem文件已被正确复制。

我的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"]

我像这样运行docker build:docker build --no-cache -t myproject:test -f Dockerfile。

我发现在github上发现的唯一类似问题是大多数情况下这种情况一致的失败,但是经常失败,我仍然不明白为什么。

任何帮助表示赞赏。

c# docker .net-core dockerfile docker-windows
2个回答
0
投票

你可以在linux上使用fuser [used file]

或者在MacOS上使用[used file]

找到那个过程的pid。


0
投票

我认为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"]

参考文献:

  1. https://docs.docker.com/engine/examples/dotnetcore/#prerequisites
  2. https://raw.githubusercontent.com/dotnet/dotnet-docker/master/samples/dotnetapp/Dockerfile
© www.soinside.com 2019 - 2024. All rights reserved.