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?