Docker Compose 1.6 logo

Install Docker Compose

Docker Compose 1.6.2 does not have a Debian package, so instead of installing its Python dependencies on the host, it can be run on-demand inside a Docker container with a helper script.

$ wget -O /usr/local/bin/docker-compose https://github.com/docker/compose/releases/download/1.6.2/run.sh
$ chmod +x /usr/local/bin/docker-compose

Organized naming convention

Instead of having Docker containers inside /var/lib/docker, deployment repositories and data volumes all over the place, the following naming convention has proven useful:

/srv/docker/   -- Docker containers (from /var/lib/docker/)
/srv/repos/    -- per-project deployment repositories
/srv/repos/project1/docker-compose.yaml
/srv/repos/project1/docker-db/Dockerfile
/srv/repos/project1/docker-web/Dockerfile
/srv/storage/  -- per-container data volumes mounted on host
/srv/storage/project1/db
/srv/storage/project1/web

Initializing such a setup can be accomplished just by moving some files, making a symbolic link, and empty directories:

$ systemctl stop docker
$ mv /var/lib/docker/ /srv/docker/ && ln -s /srv/docker/ /var/lib/docker
$ mkdir /srv/repos/ /srv/storage/
$ systemctl start docker

Afterwards bringing up your infrastructure is simple as:

$ cd /srv/repos/project1
$ docker-compose up -d
$ docker-compose logs

Project development lifecycle

First prepare an empty Git repository on your Docker server:

$ NAME=project1
$ mkdir /srv/repos/$NAME && cd /srv/repos/$NAME
$ git init
$ git config receive.denycurrentbranch false
$ echo -e '#!/bin/sh\ngit --work-tree=.. checkout -f' > ./.git/hooks/post-receive && chmod +x ./.git/hooks/post-receive

Setup your project repository and code for deployment with Docker Compose on your workstation:

$ NAME=project1 SERVER=foo
$ mkdir ./$NAME && cd ./$NAME
$ git init
$ git remote add $SERVER ssh://$SERVER/srv/repos/own.tnode.com
$ git add *
$ git commit -m 'Initial commit for deploying.'
$ git push --set-upstream $SERVER master

Afterwards bringing up your infrastructure as described above:

$ cd /srv/repos/project1
$ docker-compose up -d
$ docker-compose logs