Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to reload env_file for a specific container #4140

Closed
joaquincasares opened this issue Nov 11, 2016 · 5 comments
Closed

Add ability to reload env_file for a specific container #4140

joaquincasares opened this issue Nov 11, 2016 · 5 comments

Comments

@joaquincasares
Copy link

Hello,

I'm not sure if this task is something that compose can handle alone, or if I also need to create a ticket against the docker project, but I figured to start here.

My use case is:

  • I have ngnix, cassandra, and a web container running, via docker-compose up.
  • I've updated an env_file used by the web container.
  • Now, I'd wish to have my web container use the updated env_file.

If I try:

  • docker-compose [stop|kill] web
  • docker-compose start web

I still get my original envars that were in place at the time of docker-compose up.

How can I reload my web container to consume the updated env_file without having to do a full shutdown via docker-compose down?

Thanks for any help and guidance!

@shin-
Copy link

shin- commented Nov 11, 2016

You would need to do docker-compose up --force-recreate web, I think. Let me know if that works!

@joaquincasares
Copy link
Author

I gave that a shot, but it seems like a bit of a destructive path for just reloading an env_file:

$ docker-compose up --force-recreate web
Recreating project_cassandra_1
Recreating project_zookeeper_1
Recreating project_kafka_1
...

I understand that's caused by the docker-compose links definition. Thanks for the help though! Do you by chance have any other suggestions?

@Dineshs91
Copy link

docker exec -it <container_name> bash -c "source env_file"
docker restart <container_name> or docker-compose up -d <service_name>

@joaquincasares Can you try these and see if it helps ?

@MetricMike
Copy link

(as of 1.12.5) I think the .env_file directive in your docker-compose.yml is doing a couple things:

  1. After a container is built, but before CMD/ENTRYPOINT is called,
  2. Copy <env_file> into the container.
  3. Call source <env_file>

Based on docker-compose --verbose and https://github.com/docker/compose/blob/master/compose/config/config.py it looks like docker-compose can check the env file (and volume/network settings) for changes to the configuration.

So when you run, docker-compose up, one of two things might happen assuming your Dockerfile hasn't changed and an up-to-date image has been built:

  • No config changes? Don't do anything unless another option like --force-recreate is passed.
  • Yes changes? Reapply any config changes needed (copy and source env_file, open ports, mnt volumes). Then call the equivalent of docker-compose restart <service> and restart the container, because docker-compose can't tell what you're running inside and what services might need a restart to pick up those config changes, refresh file handles, etc.

restart skips an important step (because docker-compose has chosen to make container configuration part of the build step, which probably isn't a terrible idea), but you shouldn't need to tear everything down to do what you want.

Hope that helps! I've been wrestling with a similar problem most of today :)

@shin-
Copy link

shin- commented Jan 4, 2017

When a container is recreated the containers that depend on it are recreated as well, which is the behavior you want in most cases.
You could make a case for adding an option that simply reconnect the existing dependents to the new container instead, but it's honestly not very high on the list of priorities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants