Saturday, January 16, 2016

Dockerizing Sinatra app with reloading (Docker + Sinatra + foreman + rerun)

Lately I have been trying to learn more about Docker, so I picked up a task to dockerize a Sinatra app.

Here is an excellent training material which includes 3 hours of video about docker:
https://training.docker.com/self-paced-training

Here is another introduction to docker by Codeship:
http://blog.codeship.com/using-docker-for-rails-development/

Assumptions:
  1. You have a Sinatra app up and running using foreman.
  2. You have docker machine installed. We will be using docker compose to dockerize

Lets get started:

Step 1: Create a file named Dockerfile in the root of your project with the following content


Step 2: Create a file named docker-compose.yml in the root of your project with the following content



Step 3: Lets get reloading Sinatra app on changes working (ONLY if you want to reload your Sinatra app on changes using rerun gem)

At the moment to get rerun to work properly with Docker you have to supply --force-polling option
as mentioned here
https://github.com/alexch/rerun#vagrant-and-virtualbox

The catch is that the supporting code is only in master(as of now) and is not pushed to the latest gem.
So chances are if you install the latest version of rerun gem, you might not get the force-polling option 

use this in your gemfile development section to load the master branch of the gem
gem 'rerun', :git => 'https://github.com/alexch/rerun.git'
gem 'foreman'

Step 4: And thats all the config thats needed. Run
    a) docker-compose build
    b) docker-compose up


No comments:

Post a Comment