appsettings.json file not found issue on docker run
I am trying to build and run a docker image of the .Net Core application.
Here is what I tried so far:
- Created a .Net Core Application (.Net Core 2.2)
-
Published the application using below command
dotnet publish -c Release
-
Created a Docker file with following instructions:
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 COPY myapp/bin/Release/netcoreapp2.2/publish/ app/ ENTRYPOINT ["dotnet", "app/myapp.dll"]
-
Built the docker image with following command
docker build -t planservice -f Dockerfile .
Here, Image got built successfully. But, when I run the image, I'm getting the error as below:
C:\app>docker run -it --rm planservice
Unhandled Exception: System.IO.FileNotFoundException: The configuration file 'appsettings.json' was not found and is not optional. The physical path i
s '/appsettings.json'.
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load(Boolean reload)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationRoot..ctor(IList`1 providers)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at myapp.Program.GetConfiguration() in C:\app\MFPServices\myapp\Program.cs:line 64
at myapp.Program.Main(String[] args) in C:\app\MFPServices\myapp\Program.cs:line 16
Solution 1:
As per @Jawad suggestion, I have modified my Docker file to navigate to /app folder. appsettings.js should be present in current location to run.
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
COPY myapp/bin/Release/netcoreapp2.2/publish/ app/
WORKDIR /app
COPY . .
ENTRYPOINT ["dotnet", "myapp.dll"]
Now, it is working properly.