Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart docker with different environment variable

I have a docker-compose that has

myimage:
  image: myimage:latest
  environment:
    MY_VAR: "something"

the container uses MY_VAR internally, and sometimes in automated testing I'd like to restart that specific container with a different MY_VAR (to simulate a process restart with different environment variable settings)

Is there a way to do this while keeping the rest of the docker-compose container up?

like image 795
Nick Ginanto Avatar asked Jan 22 '17 05:01

Nick Ginanto


1 Answers

Like @robin.thoni said, would need to recreate the container to change the MY_VAR value, but you could make the process simpler by using a environment var in the compose YML, like this:

    myimage:
      image: myimage:latest
      environment:
        - MY_VAR: ${A_ENV_VAR}

And running the container like this:


A_ENV_VAR=test docker-compose run myimage

like image 93
Lucas dos Santos Abreu Avatar answered Oct 16 '22 06:10

Lucas dos Santos Abreu