Reputation: 32130
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?
Upvotes: 15
Views: 24014
Reputation: 596
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
Upvotes: 14
Reputation: 1721
You can't do that, you have to recreate a container, as environment variables are given in the run
command (even with a docker-compose).
Upvotes: 3