Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appSettings.json for .NET Core app in Docker?

Tags:

I am running a .net core app in a docker container. Here is my docker file (just to build a dev environment):

FROM microsoft/dotnet:1.0.1-sdk-projectjson 
ENV ASPNET_ENV Development
COPY bin/Debug/netcoreapp1.0/publish/ /root/
EXPOSE 5000/tcp
ENTRYPOINT dotnet /root/AVP.WebApi.dll

I have an appSettings.Development.json file in the /publish/ folder. If I build and run this Docker file, I end up with a strange issue where the .NET app can't find the appsettings it needs to start (they're in the appSettings.Development.json file).

I have confirmed that from the command line in windows if I run dotnet publish/AVP.WebAPI.dll the app throws the same exceptions for missing configuration settings. However if I cd to /publish and run dotnet AVP.WebAPI.dll the app starts and runs just fine.

Any ideas how to change my docker file so it will run the app properly with the appSettings.Development.json values? (I've also tried to run the app with all the values copied into the regular appSettings.json files with no luck)

I've also tried running a the COPY command to / instead of /root and doing dotnet AVP.WebApi.dll as the entry point, but that results in the project being unable to find dependencies.

like image 822
Sam Ellis Avatar asked Mar 03 '17 06:03

Sam Ellis


1 Answers

Try replacing this line:

ENV ASPNET_ENV Development

With this:

ENV ASPNETCORE_ENVIRONMENT Development

Your original Environment Variable name was used in older .NET Core, but has been changed. It can be a pain finding tutorials, etc. for .NET Core because of all of the changes that have happened since it first started!

Don't get me started on project.json files!

More info:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments

like image 88
Andrew S Avatar answered Oct 22 '22 13:10

Andrew S