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/

Removing docker and reinstall

Today I had some issues with docker 1.2 and had to remove it and re-install, this fixed my problem. The issue was when I issued the command “docker run xxx” docker would fail to load shared libraries. To fix I used the following,

sudo apt-get remove --purge lxc-docker

sudo apt-get autoremove --purge

sudo apt-get install lxc-docker

Do not forget you need to have the correct repos added before the above will work, it assumes you have them added already as you are removing docker, if not and you wnat to install docker check out a previous post, https://cloud-guy.net/2014/09/24/upgrade-or-install-docker-1-2-0/.

Hope this helps others……………………..

 

Upgrade or Install Docker 1.2.0

Some time ago I posted on installing Docker 1.0, today I got a chance to Upgrade from 1.0 to 1.2.0, the upgrade was easy here is what I did, the machine already has Docker 1.0 installed,

$ wget -qO- https://get.docker.io/gpg | sudo apt-key add -
$ sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
$ sudo apt-get update
$ sudo apt-get install lxc-docker

Check out the following link for lots of info on Docker 1.2.0 http://blog.docker.com/category/docker-releases/

Stuck in login loop (Ubuntu 13.10)

This morning I attempted to login into my dev machine by entering the password and pressing enter key. The screen would go black for a sec or two and then bring me back to the enter login screen again, I repeated this a couple of times. To fix this is easy, just press ctrl + alt + F2 to bring you into a console/terminal and login using you normal user name and password, enter ls -lah and you will see the the .Xauthority owner is root and is a member of the root group. You need to make .Xauthority part of you user name group and you also need to be the owner, this is easy, just run this chown username:username .Xauthority, press ctrl + alt + F7 to go back to the login screen and login and all should be good.

 

How it saves you some time…………………