0

I have a container running with env variable X=value. This was set when container was built from .env file. Is it possible to update this variable in the container itself?

I execd into container using docker exec -it <containerid> sh, then tried running env X=newValue. After this all env variables print out and the X value is shown as 'newValue', but when I run env again, it still shows X as 'value', seems as it rolls back to it. Is there a way to update this without the need to stop current container and rebuilding it from scrach? Thanks

Powisss
  • 1,072
  • 3
  • 9
  • 16
  • 1
    You cant for a created container. You need to remove it and re-create it. – Marc Feb 02 '23 at 10:53
  • 1
    The linked question has many answers, but they essentially boil down to ineffective modifications to shell dotfiles that won't affect the running process, or hacks around changing Docker internals. Deleting and recreating the container is extremely routine and it's the right answer here. (Consider it the same as ^C and re-running the process without Docker.) – David Maze Feb 02 '23 at 12:09

0 Answers0