Running PHP and Nginx on Docker

One of the major projects I'm undertaking at the moment is to gradually move a large hosting infrastructure onto Docker containers.

One of the major projects I'm undertaking at the moment is to gradually move a large hosting infrastructure onto Docker containers.

Since we use Capistrano for a deployment stack our goal is to have each site / project rebuild its container on cap deploy.

Eventually the plan is to reduce the persistent footprint of a project down to its database data directory and a persistent storage directory for files / user uploads.

The engine for the deployment is a slightly enhanced Capistrano called capdocker (not open source currently) that takes care of building the containers.

Example Deploy

The usage is extremely simple here's an example Capfile:

require 'rubygems'
require 'capdocker'

set   :application,     "docker_tester2"
set   :app_port,        "49157"

Incredibly Powerful Deploys

The real power in this strategy is in how easy it is to deploy projects to a live / staging server. Want to send a feature branch demo to a client for sign off? All you need to do is:

  1. Checkout to the feature branch - git checkout wip-feature
  2. Use a new port in the Capfile - set :app_port, "49158"
  3. Type: cap deploy

You can even emit the port setting and capdocker will just use a random one. Deploys take around 20 seconds after which time you're presented with:

  command finished in 1234ms
  * 2014-02-15 13:56:53 executing `deploy:finish'
 ** Application deployed to: http://yourserver.com:49158

Next Steps

This is intended to be an ongoing series, I'll follow it up with an example of our Dockerfile which builds an entire Nginx, PHP and Mysql stack on top of the base Ubuntu.