I am trying to understand method to overwrite environment variable inside running docker container.
I tried below options as suggested over other SO posts. Every time I set env variable via docker exec -e it shows me env variable as set. On the very next run it disappears.
Command to start docker:
docker run -itd --rm -e VAR1=test_var1 -e VAR2=test_var2 --name "test" phusion/baseimage:18.04-1.0.0
Running docker exec to set env variables
cloud_user@vijaygharge1c:/var/lib/docker$ docker exec -it -e VAR4=test_var4 test env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=de9cf4253ae9
TERM=xterm
VAR1=test_var1
VAR2=test_var2
DEBIAN_FRONTEND=teletype
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=en_US.UTF-8
VAR4=test_var4
HOME=/root
cloud_user@vijaygharge1c:/var/lib/docker$ docker exec -it -e VAR4=test_var4 test env | grep VAR
VAR1=test_var1
VAR2=test_var2
VAR4=test_var4
cloud_user@vijaygharge1c:/var/lib/docker$ docker exec -it -e VAR3=test_var3 test env | grep VAR
VAR1=test_var1
VAR2=test_var2
VAR3=test_var3
cloud_user@vijaygharge1c:/var/lib/docker$
Docker version:
cloud_user@vijaygharge1c:/var/lib/docker$ docker -v
Docker version 19.03.12, build 48a66213fe
cloud_user@vijaygharge1c:/var/lib/docker$