Reload configuration when env variable has changed

前端 未结 2 1208
逝去的感伤
逝去的感伤 2021-01-05 04:42

In Startup.cs file I have

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
           


        
2条回答
  •  情话喂你
    2021-01-05 05:07

    Are there any ways to change a value of env variable at runtime (without restarting docker container)

    No. (And even a restart isn't enough: you need to delete and recreate the container.)

    This follows the ordinary Unix model. A process can set the initial environment for its child process, but once it's exec'd the child, it has no more control over the environment any more. docker exec launches a new process in the container namespace and so if you change an environment variable there it will only affect that process and not the main container process.

    There are a significant number of options that can only be set during the initial docker run command. This includes environment variables, and also includes volume mounts and published ports. Critically, it also includes the underlying image: if you ever have a new build of your application, or need to update the underlying OS distribution for a security issue, you will be forced to delete and recreate your container. In my experience docker rm is extremely routine, and you should plan for it to happen regularly.

提交回复
热议问题