Barnacle

All I want from Docker is convenience and the ability to run isolate services. I don't want to push to registries, tag images, manage containers, etc. I created this simple gem to hide these complexities.

There are only four ways to run barnacle, and you can probably guess what they do.

barnacle up
barnacle down
barnacle status
barnacle enter

Requires

docker version >= 1.5.0

some reasonable version of ruby

Install

This is a ruby script packaged in a ruby gem.

shell> gem install barnacle

or Gemfile:

gem 'barnacle'

Setup

Place your Dockerfile and an optional file named config.yml in your services root directory. barnacle will look for these files in a directory named barnacle. The Dockerfile will probably contain an ADD statement to include some or all of the directory tree - but that's up to you. Your Dockerfile will definitely need a CMD because there's no way to pass arguments to barnacle - a design decision for simplicy, the objective of barnacle.

my_service/
├── app
├── barnacle
│   ├── config.yml
│   └── Dockerfile
├── bin
└── lib

Execution and Defaults

Defaults:
  • detach = true
  • [name] = current directory name
  • [hostname] = current directory name

If you want to override any defaults put them in the barnacle/config.yml file described in the next section.

barnacle up (runs)
docker build -f barnacle/Dockerfile -t [name]
docker rm -f [name]
docker run --detach=true --name=[name] --hostname=[hostname] [config.yml switches] [name] 
barnacle down (runs)
docker stop [name]
barnacle status (just highlights line with [name] in the name column)
docker ps -a
barnacle enter (executes)
docker exec -ti [name] bash

config.yml

This file is made up only of command line switches passed to docker commands.

Example config.yml:

docker:
  privileged: true
  v: 
    - /sys/fs/cgroup:/sys/fs/cgroup:ro
    - /var/log/relay:/var/log

The above config.yml results in these additional command line switches for $>docker up

--priviledged=true -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /var/log/relay:/var/log

Workflow

Just a suggestion for production deployment.

  1. Get changes up to production server (git push/pull, rsync, floppy, whatever)

  2. Log into remote host... cd to service's directory

  3. barnacle up

If you are more sophisticated you might combine all these steps in a single command - like a rake task utilizing ssh -c for the remote commands, or even something like Ansible.

No image repository is needed except for the base image on the first run. If you keep your images up on the production server, and are smart about your Dockerfile, this should be a very quick deployment.

Note: if you are deploying rails don't forget to put 'bundle install', compile assets, and tell the web server of the changes in your Dockerfile. (research into caching as much 'bundle install' as possible)

Musings on the docker way vs. the barnacle way

If you are working for hipsters.com with a valuation of a trillion dollars and are deploying one new host per second then the barnacle way is the wrong way.

One reason why is that barnacle will build the entire final image at least once on every new server and this can take minutes. Another reason is that you might pass new deployments around as images to devops.

If you're a graying neckbeard that privisions new hosts as often as you provision new underpants then the barnacle way can work. You don't need to move things around as docker images. You move deployments around as directories with scp, rsync or even ftp. To you a docker image is just a build cache for a new container and it stays where it is.

Docker: is cool and innovative.

Barnacle: is a feeble ruby script written by some slacker who thinks docker is too complicated for him.

Docker: 'deployments' are passed around as images, probably using a docker registry.

Barnacle: 'deployments' are just folders with a barnacle directory containing a Dockerfile and an optional config.yml file. Except for the base image for the original build a docker registry isn't used.

Docker: the docker host doesn't really see anything other than new images arriving for deployment.

Barnacle: you'll have deployment directories laying around. They probably got there from by git or rsync.

Docker: images are built on dev or automatically at the official docker registry.

Barnacle: images are built on the production host, kept around just for caching purposes, and are otherwise given no notice.

Contributing

  1. Fork it ( https://github.com/[my-github-username]/barnacle/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request