Autodock. The docker container automation tool.
Python Shell
Latest commit e6f6511 Mar 25, 2014 @cholcombe973 A slew of changes that bring this up to docker 0.9 support. I also ch…
…anged over to using the phusion baseimage. You can pull this image from https://github.com/phusion/baseimage-docker.git
Permalink
Failed to load latest commit information.
Dockerfile Rolling up my changes from my mercurial repo Dec 20, 2013
LICENSE A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
README.md A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
apache.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
app.py Adding the first pieces of an edit command and found a bug in the pin… Feb 5, 2014
appbackup.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
autodock.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
bootstrap.sh Adding notes about modifying the bootstrap script and updating the ba… Feb 10, 2014
circularlist.py Breaking out the verify code into a separate class Dec 3, 2013
edit.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
etcd.py A few changes are needed to support the latest version of etcd Feb 10, 2014
formation.py Adding the first pieces of an edit command and found a bug in the pin… Feb 5, 2014
load.py Initial commit Nov 11, 2013
manager.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
nginx.py Initial commit Nov 11, 2013
start.sh A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014
systemd.py Initial commit Nov 11, 2013
upstart.py Initial commit Nov 11, 2013
verify.py A slew of changes that bring this up to docker 0.9 support. I also ch… Mar 25, 2014

README.md

Autodock

All the deliciousness of a crazy KFC combination sandwich...none of the shame.

Autodock is a docker automation tool. This tool will help you spin up docker containers faster than ever!
It automatically sorts servers in your Docker cluster by lowest load. It then distributes the containers you want to create among them.
After bootstrapping the containers with Paramiko and Salt it saves this information to the ETCD cluster.

Autodock was designed to use saltstack and etcd for configuration management and replication.

Getting Started

Autodock is currently only tested on Ubuntu 13.04.
Testing and pull requests for other platforms are welcome.
Autodock has a few requirements that need to be in place before it will function properly.

  • Docker 0.8+ highly encouraged due to bugs
  • Saltstack
  • Python 2.7+
  • Python Paramiko to ssh into containers
  • Etcd
  • GoLang 1.2, so Etcd can function
  • A docker base container

Usage

  1. Log into a salt master node. Setting up Multi Master is highly encouraged!

Synopsis

autodock {list,verify,backup,create}  
Autodock is split into several subcommands.  Each subcommand has its own options:  

list usage:   autodock list [-h] -u USERNAME 
backup usage: autodock backup [-h] -u USERNAME -f FORMATION
create usage: autodock create [-h] -u USERNAME -f FORMATION [-n NUMBER]
                       [-c CPU_SHARES] [-r RAM] -s HOSTNAME_SCHEME
                       [-p PORT_LIST] [-z HOST_SERVER] [-d DELETE]
                       [-v VOLUME_LIST]

example: autodock create -f owncloud -n 3 -c 100 -r 100M -h clwebdev
Which will cause it to spin up three containers with a formation name of owncloud, 10% of the cpu allocated, 
100MB of ram and a hostname of clweb001, clweb002, clweb003, and register this formation with the nginx 
load balancers. The formation just means clweb001-003 all serve the owncloud web application. Once the 
container starts up I'll ssh into each container, bootstrap salt and setup a salt-call cron job to setup 
the container. All we need is to have a salt top.sls matcher in place to apply whatever changes we want. 
Following our example it would be install nginx, install uwsgi, hg pull the latest from the repo, setup 
the nginx hosts file and start both nginx and uwsgi.

Description

list options:

  • -u, -username
    • The username who owns this formation.

backup options:

  • -u, -username
    • The username who owns this formation.
  • -f, --formation
    • The formation to backup

create options:

  • -u, --username
    • The username who owns this formation. Each user will be able to see only their containers.
  • -f, --formation
    • A Formation is a set of infrastructure used to host Applications. Each formation includes Nodes that provide different services to the formation.
  • -n, --number
    • The number of containers to build, ex: 1
  • -c, --cpu_shares
    • A percentage of the cpu that the container is allowed to use. CPU shares (relative weight) is a number from 1-1024. 102 shares would equal 10% of the total cpu.
  • -r, --ram
    • Memory limit (in megabytes)
  • -s, --hostname_scheme
    • A base hostname scheme to use for the containers. Ex: dlweb would produce containers with hostnames of dlweb001, dlweb002, etc.
  • -p, --port
    • Add ports to map to the container. host-port:container-port. If the :is missing then host-port and container port are assumed to be identical
  • -d, --delete_formation
    • Delete a formation of containers all at once.
  • -v, --volume
    • Create a bind mount. host-dir:container-dir:rw|ro. If "container-dir" is missing, then docker creates a new volume.
  • -x, --verify
    • Verify that the cluster is in the correct state and move containers around that are on dead hosts.
  • -z
    • Force the container to be brought up on a particular host server

Example Usage

root@server01:autodock# python autodock.py create -u cholcomb -f clweb -n 1 -s clweb
2013-11-03 23:37:48,805 - urllib3.connectionpool - INFO - Starting new HTTP connection (1): server01
2013-11-03 23:37:58,961 - root - INFO - Checking if 9023 on server02 is open with salt-client
2013-11-03 23:37:59,130 - root - INFO - Adding app to formation clweb: clweb001 cpu_shares=100 ram=104857600 ports=22 host_server=server02
2013-11-03 23:37:59,130 - root - INFO - Starting up docker container on server02 with cmd: docker run -c=100 -d -h="clweb001" -m=104857600 -p 9023:22 server02:5000/sshd /usr/sbin/sshd -D
2013-11-03 23:37:59,353 - root - INFO - Bootstrapping clweb001 on server: server02 port: 9023

Salt State Files

I have a state file setup for any hostname starting with cl* so clweb001, cldjango001, etc will all match my regex expression in the top.sls state file in Salt. Try to keep your Salt installs as minimal as possible. The containers can really bloat in size easily.

Testing the Code

root@server01:autodock# python -m unittest -v etcd.TestEtcd
test_a_setkey (etcd.TestEtcd) ... ok
test_b_getkey (etcd.TestEtcd) ... ok
test_c_deletekey (etcd.TestEtcd) ... ok
test_d_directorylist (etcd.TestEtcd) ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.193s

OK
ETCD JSON Objects

The docker cluster in etcd key is called: docker_cluster
The JSON object that stores container configurations looks like this:
A directory for the username /cholcomb
A key for each formation: /cholcomb/owncloud and a value of:[ { "hostname": "owncloud01", "cpu-shares": 102, "ram": 100, "port": 8080, "host-server": "dldocker01", "mounts": [...]}, {...}]
A formation consists of a list of apps