1

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?

dustyburwell
  • 121
  • 1
  • 3

1 Answers1

1

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.

Erik Dannenberg
  • 306
  • 1
  • 5
  • 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 07: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 08:09