Skip to content
Plaristote edited this page Apr 8, 2016 · 3 revisions

Crails docker module

Crails comes with a Docker module, providing you with a template to create your container, and tools to run the container. The default template is based on debian:jessie.

Install

Install the docker module with the following command:

$> crails module docker install

Building the container

Once you've made sure that docker was running on your machine, and installed the docker module in your application, you may use the docker/build command (from the root folder of your crails application) to build the container.

If you wish to interact with the container by yourself, note that the container's name will follow this schema: crails/project_name

Interact with the application from the container

You may also interact with your application from the docker container by opening a shell from the container. This can easily be done by using the docker/shell command.

Customize your container

The container can be customized using the docker/base directory. It contains the Dockerfile, as well as a few files used to download and compile dependencies of crails.

You may comment out the dependencies you don't need (for instance, mongo-cxx-driver if you don't use mongodb, odb if you don't use the crails-odb module, libmemcached if you don't use the crails-cache module). If your application needs any other 3rd party libraries, you need to compile them from the Dockerfile.

Make an application package

The docker module comes with the make-application-package.sh script. It will build your application, and export in a directory every binary and configuration file that your application needs to run on a machine similar to the one described in the Dockerfile.

Note that:

  • By default, the application package is built in production mode (no debug information, exception backtraces, if enabled, will only be available from the logs, ...)
  • It will assume that any dependencies of the Crails application found in /usr/local needs to be exported.
  • Anything that's not in /usr/local is supposed to already be present on the target machine, and won't be exported in the application package.

Hence, if your application uses 3rd party libraries, you need to make sure that the binaries are installed in /usr/local/lib. If they aren't, you'll need to edit the docker/base/make-application-package.sh file, to make sure that all your libraries are properly exported within the application package.

Your application package will be available in the docker/crails-build directory. You may create an archive from that folder and upload it to your production server.

For Heroku users

WARNING this is not up to date, cedar14-compat has been replaced by gcc4-compat.

The cedar14-compat branch contains a slightly different version of the Docker module, based on the heroku:cedar14 container. It also comes with a deploy script which should allow you to deploy your Crails project on the Heroku platform in a single line of command:

  docker/deploy -a my-heroku-application

The deploy script will build your application, configure your Heroku app, and deploy your application package to the Heroku app, if possible. For good measure, it will use a buildpack that ensures all the dependencies of your crails application are present within the application package you're deploying.