Appsettings session is not read when running on Docker Container

Asked

Viewed 20 times

0

Refer to Docker-Compose reading of Appsettings. When I run through Docker-Compose, I can’t load the file appsettings.

Linha em que estoura o object reference

That’s why, only when run by Docker-Compose it does not find the Appsettings session and I get a object reference on line 19.

I was able to analyze that:

  1. The file is inside the Container. Conteúdo do container

  2. Environment set correctly by Docker-Compose Environment está para Production

  3. That mistake only happens when I run Docker-Compose via command-line. That is, starting the application by visual studio, it reads the appsettings correctly. Even I’ve even run a Publish and locally startei successfully through the published . dll.

  4. Desired configuration in appsettings.Production.json (i even put on all to see if the problem was something with Environment, but it seems to be even about reading Appsettings in the file). Appsettings (dados fictícios)

  • 1

    access the container and check the file paths. Remember that if you are using linux containers, the paths are case sensitive, to avoid problems can use everything tiny. Put logs in the tbm app to validate if you loaded the files correctly

  • I copy everything into a folder /app, the contents of this is item 2 I marked. About being case sensitive, I try to read the session "Appsettings" as it is in the file, and Environment I define as - ASPNETCORE_ENVIRONMENT=Production, I think they are the points where it would disturb, I do not see another in mind. The file of the Compose is in LF format.

  • Actually, I reviewed it carefully and it was an appsettings call. You can post as an answer in case someone goes through it.

1 answer

0


As said by @Ricardo Pontual, the problem was even by the case sensitive (which is considered in linux).

I went through the entire code and found the difference in an appsettings call.

 var builder = new ConfigurationBuilder()
            .SetBasePath(hostEnvironment.ContentRootPath)
            .AddJsonFile(path: "appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile(path: $"appsettings.{hostEnvironment.EnvironmentName}.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.