Docker container configuration

Recently I was asked “what is the best way to present configuration to a docker container”, my initial answer was to use environment variables and depending on the application one could use a dynamic approach and use ETCD to hold the configuration and have the container software pull it’s configuration from ETCD and have the ability to watch for ETCD configuration changes and preform updates as required.  Since then I have being thinking hard to figure if their were other approaches to this problem, one that would work very well is creating a directory on the host, placing the configuration files in the directory and having the directory mounted in the container at run time. My initial reaction to this method was,  i did not like it, but the more I though about it I final concluded it is a valid approach and if the correct tooling was put in place, one could have a clean method of presenting any configuration to the container services at run time.

Lets do a quick example, let’s create a config directory in the hosts ‘tmp’ directory, create a config file and then run a docker container interactively and go to the docker/tmp/config directory and see our config file.

Lets create a directory on the host thta we can use as the volume in the container to hold our configuration

mkdir /tmp/config

Now lets create a quick config file in the /tmp/config directory so we can see it their when we go to the config directory in the container.

touch /tmp/config/config.conf

Now lets create a Ubuntu container with the the volume mounted

docker run -t -i -v /tmp/config:/tmp/config  ubuntu:14.04 /bin/bash

Now we are in the container, you can change directory to the /tmp/config and vitrify that the config directory is present and that you can see the config.conf file. You can monitor this file for changes inside the container and edit/write to this file form the host.

References

[1] This is a link to a previous post on etcd in a Docker container, this is a quick way to start playing with etcd. https://cloud-guy.net/2014/07/03/etcd-in-a-container/

[2] Etcd code on github : https://github.com/coreos/etcd

[3] Etcd overview: https://coreos.com/using-coreos/etcd/

[4] Etcd getting started: https://coreos.com/docs/distributed-configuration/getting-started-with-etcd/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s