I hacked together an app named dockit using Go in order to manage a simple environment; one with webapps and a reverse proxy to route traffic to them.
This is not supposed to be a general-purpose tool, but rather an example of how wiring up Docker environments using Go is...
So get some ideas here (or use this as a starting point) and go build your own toolkit to codify (no pun intended) the conventions, opinions, and nuances of your environment in a format that you can maintain and test.
All of this info is repeated on the project page, so if you want to dive right in, go there now.
By default, dockit looks for a config.json file in your current directory, connects using unix:///var/run/docker.sock, and keeps track of running containers with "pid" files in /var/run/dockit-containers.
You can define services for your environment in the config file, and specify ports, environment variables, and dependency services (which are translated into links.)
Included in this repo, is an example config to build an environment with a webapp (the included webapp-ex/) fronted by a reverse proxy (Hipache.)
The config specifies:
The webapp entry point script (webapp-ex/start.sh) uses the link and host env var to register the webapp with Hipache and to deregister on shutdown.
Here is a copy of `config.json` from our example environment:
(the image benschw/go-webapp was built from the contents of the webapp-ex directory)
Pull the example containers:
Start the Services:
This will start up the Hipache service and then the WebApp service, and it will register the private ip:port of the WebApp container with Hipache (see webapp-ex/start.sh) under the name webapp.local.
add "127.0.0.1 webapp.local" to your "/etc/hosts" file, and the example webapp should be available at http://webapp.local
This will only stop the WebApp container (and deregister from Hipache); Hipache is still running. To stop it too, run:
Note the containers are still there in a "stopped" state, and a subsequent -start will run new instances.
I can't stress enough that dockit is not supposed to be a useful app, but rather something to get you thinking about how you can add testability and maintainability to your environment (and maybe to help you figure out how to make use of fsouza's Go client for Docker.)
Hopefully it can help you add some stability to your environment's wiring.
If (like me) this is your first foray into Go, here's a gist to help you build the examples.
comments powered by Disqus