Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GenerateRuntimeConfigurationFiles task failed unexpectedly

I'm getting inconsistent errors when building my docker image. This fails approximately 1 out of 3 times, if i keep running docker build.

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

my 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 .

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.

Any help is appreciated.

like image 902
KristianMedK Avatar asked Nov 17 '22 07:11

KristianMedK


1 Answers

I think some of the commands in the Dockerfile need to be changed.

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

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

like image 115
Gopi Avatar answered Nov 20 '22 00:11

Gopi