0

I have created a .net core web application with 3 different app settings file

  • appsettings.json
  • appsettings.DEV.json
  • appsettings.PROD.json

I have the following code in the startup.cs file

 public Startup(IHostingEnvironment env)
 {
      var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
          .AddEnvironmentVariables();
      configuration = builder.Build();
 }

During debugging on visual studio, appsettings.js is replaced based on the env variables(eg: if env=dev -> i got configuration variables from appsettings.DEV.json and if env=prod -> i got configuration variables from appsettings.PROD.json )

But after dockerizing my application, this is not working. I have used the following docker command to run my application.

docker run \
            --detach \
            --restart always \
            --name $name \
            --env ASPNETCORE_ENVIRONMENT=$env \
            --env containerName=$name \
            reponame

Anything is more needed for docker run?

1 Answer 1

2

Everything looks good from my perspective, but please pay attention to the fact that Linux (if it's your host OS) is case sensitive. ASP.NET Core respects whatever the host OS conventions are in place.

Can you confirm that --env ASPNETCORE_ENVIRONMENT=$env is actually -e ASPNETCORE_ENVIRONMENT=PROD or -e ASPNETCORE_ENVIRONMENT=DEV?

-e ASPNETCORE_ENVIRONMENT=Prod won't work. -e ASPNETCORE_ENVIRONMENT=PROD will work in your case.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.