dominionenterprises/mongo-queue-php — pull request #28 by nubs (2014-07-23 22:01:53+00:00)
Title: Use fig instead of dockerBuild.php.

dockerBuild.php was a hack I put together just to test out how orchestrating the separate containers would be. Turns out, this is a problem that needs more than a simple hack to solve. The root of the issue comes down to the edge cases where the state of various containers isn't being properly handled: it tries to run containers that already exist in some cases and doesn't run ones that have been stopped in others.

Rather than beefing dockerBuild.php out into a larger script to handle all this (complicated!), I took a look around to see what is on offer:

* [fig](http://fig.sh) - nice and simple and built to solve this exact
problem
* [kubernetes](https://github.com/GoogleCloudPlatform/kubernetes) -
Potentially useful in a production environment, but a bit overkill for
our problem.
* [fleet](https://github.com/coreos/fleet) - Very interesting, but the
ties to systemd and etcd make it difficult to use in all environments.
* [ansible](http://docs.ansible.com/docker_module.html) - A nice
chef-esque way of doing things, but requires a lot of extra
configuration to manage and feels funny running against localhost.

All in all, I couldn't find much out there to really compete with fig for this usecase although I'm sure some other small attempts exist. fig is a python-based command, but it is distributed as a linux binary, so python doesn't really come into play. It takes 30 seconds to setup and has a very intuitive CLI (coming from Docker) with decent documentation via `fig help ` and via its website.

Implementing the switch is fairly straightforward. Take the primary docker run line and extract the links and volumes into the fig.yml configuration as given. Create a "build" image that is the primary build for the package. Additional services can also be added (mongo, redis, etc.) and because they are linked to the "build" image, they will be started first before the build container is run.

The set-env.sh change is related to a small difference in how fig names its containers compared to how dockerBuild.php does. It takes a more convention-driven approach that allows for multiple copies of a single service and doesn't provide configuration for overriding its service names (that I can tell).