In a CI environment, I want to pass credentials for reaching authenticating to our internal Gems server into docker containers being started within CI jobs. I would like to be able to configure the docker daemon to always fetch the variable from the environment on the agent and push it into all containers ever started.

Is it currently possible to do this?


The easy way:

$ export HOSTVAR=somevalue
$ docker run -it --rm -e CONTAINERVAR="${HOSTVAR}" someimage

This will of course not push changes to HOSTVAR into running containers, you will also need to make sure to recreate every running container should HOSTVAR change. Depending on your setup this might be sufficient, i.e. every test runs in a new container.

If you have long running containers you will have to rely on some form of shared configuration daemon like etcd running inside your containers. It's fairly simple to set up and allows listening for changes in a centralized configuration key/value store. Check the etcd docs for an example.

  • I specifically don't want to start each container with a -e argument. I would like to set something up in the environment such that all new containers have the variable implicitly passed into them. – dustyburwell Jan 29 '16 at 7:42
  • Read the 2nd part of the answer. There are a couple of options, but all of them will require some effort on your part. If you checked the linked etcd example, it's fairly trivial to listen for config change and trigger a small shell script in your containers that updates environment variables. – Erik Dannenberg Jan 29 '16 at 8:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.