.NET Core reloadOnChange settings in container

  .net-core, docker

I have a simple .net core console app that just prints in screen a string that reads from the settings

private static void Main(string[] args)
    var builder = new ConfigurationBuilder()
        .AddJsonFile("Settings/appsettings.json", optional: true, reloadOnChange: true);
    var configuration = builder.Build();

    while (true)
        var greeting = configuration.GetSection("MySettings").GetSection("Greeting").Value;

When I run it locally the reloadOnChange works fine and I get the change in the string seamlessly.

So now I was trying to run it within a containe, for which I added a simple dockerfile

FROM microsoft/dotnet:2.1-sdk

COPY *.csproj ./
RUN dotnet restore

COPY . ./
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "out/DynamicConfig.dll"]

And tried to test that if I mounted the local appsettings file I would get that reloadOnChange behaviour, initially I tried to mount just the file but after reading some potential issues (although I think they could be overcome) decided to move it under that Settings folder. Yet, I don’t get it to change

The command that I use to run it is

docker run -it –rm -v /${PWD}/Settings:/app/Settings myimage

It has a slight different syntax for the usage in a Windows machine (and have even tried to map to /app/out/Settings with no luck neither)

Would love to hear something around the reasons this doesn’t “work”


Source: StackOverflow