Make lxc-attach work again with docker 0.9

Docker 0.9 was released a few hours ago. Amongst other major new features, it contains a new "engine driver" abstraction to make possible the use of other API than LXC to start containers. It also provide a new engine driver based on a new API library (libcontainer) which is able to handle Control Groups without using LXC tools. The main issue is that if you are relying on lxc-attach to perform actions on your container, like starting a shell inside the container, which is insanely useful for developpment environment but strongly discouraged on production environemnet, you'll notice that the new libcontainer engine doesn't allow you to use lxc-attach anymore :

lxc-attach: '3ac29fb18e7c3886c46bb99aff4e74e951c23ea26c6f55a38fc2c26e6037da1d' is not running
lxc-attach: failed to get the init pid

This is directly related to the fact that docker doesn't use lxc-start to start your container anymore with that engine. As a consequence, the userland LXC commands have no access to the container, even though the container is running fine, and its ID matches.

And it's the default engine since 0.9, even if you're upgrading from and older release.

Luckily, LXC engine driver support has not been dropped. It will even continue to be fully supported by docker.

To enable it back has the default engine driver, you can use the new -e flag with the 'lxc' option when starting your docker daemon.

If you're using debian or its derivatives, it's simply a matter of adding '-e lxc' to the docker daemon startup option in /etc/default/docker :

$ sudo cat /etc/default/docker
(..)
# Use DOCKER_OPTS to modify the daemon startup options.
DOCKER_OPTS=" -e lxc"
(..)

And then restart the docker daemon :

$ sudo service docker restart

Note : If you had any container running prior the docker deamon restart, you should restart those too, as they are still not restart with lxc-start.

Hope it helps bringing back your beloved lxc-attach feature !

As a final note, these instructions apply also for a new installation of docker. But since the new binaries doesn't strongly depend anymore on LXC userland, the lxc package isn't automatically installed wich lxc-docker on ubuntu/debian. In that case, you must also manually apt-get the lxc package :

$ sudo apt-get install lxc