Recently I've been looking at involving Docker containers into running a few Laravel applications - possibly removing provisioning and deployment scripts from the process completely. I'm going to record some notes on my learning here (work in progress).


Dokku is an application that leverages Docker to provide a self-hosted Heroku-style PaaS system. If you haven't used Heroku, it allows you to use git to deploy your application by simply pushing to a Heroku remote. I've toyed with self-hosted variants of this before (bare repositories and post-receive hooks) but it's always been fairly temperamental and easier to use deployment scripts.

I came across Vance Lucas' post on running PHP apps on Dokku which is an excellent guide into getting started with this.

Out-of-the-box, Dokku will detect that what environment your application needs by looking for packaging files (e.g. composer.json tells it to install nginx and PHP). However, you may still need to do a bit of configuration. Fortunately, Dokku can use buildpacks (configuration scripts) built for Heroku - using the most popular PHP buildpack you can have a nice environment set up quickly. It feels quite handy to be able to configure your deployment environment from the composer file.

Boilerplate Laravel project

I'm starting by getting a boilerplate Laravel application runing first. I'm using a DigitalOcean droplet pre-configured with Dokku (basically following Lucas' blog post) and the CHH PHP buildpack.

  1. composer create-project laravel/laravel .
  2. Remove composer.lock from .gitignore
  3. Set the default database to sqlite (since it's already in source control...)
  4. Configured composer.json. The Silex configuration pretty much works for any single-entry-point app and is fine for Laravel as long as we update the document root.

The only real issue I experienced was a permissions error where Laravel was writing /app/storage/meta/manifest.json, which was solved with a chmod.

"extra": {
    "heroku": {
    	"framework": "silex",
        "document-root": "public", (the only change from the silex env)
        "index-document": "index.php", (default, but added for completeness)
        "compile": [
            "chmod -R 777 app/storage"

Small reporting application

(Todo) I have a small application that indexes uploaded log files reports their contents in a web application. Currently it's deployed using a few Capistrano tasks which will need to be ported. It also involves an MySQL and an FTP server (environment requirements) so this might need a custom Dokku plugin or buildpack.

Larger application

(Todo) I have a larger application with queues (Beanstalkd - plugin or ext. container?), externally hosted database (perhaps in a separate container?) and a bunch of dependencies to install. Will be interesting to see what deployment time is like.