Real-world Rails development with Docker (Part 4)

Series Index

Part 1: Introduction
Part 2: Setup
Part 3: Controlling the stack
Part 4: The Rails app
Part 5: Gotchas and final thoughts

The Rails app

Check out the demo application source code and prepare the application.

$ git clone
$ cd docker-demo-app
$ bundle install
$ rake db:migrate


Over in our docker-demo-stack, make sure that the path we mount in the Nginx container actually mounts the correct path to your demo Rails app. This is in the docker-compose.yml file at this line:

- ${PWD}/../docker-demo-app:/app

You can use a relative or absolute path, just ensure that the part on the left of the colon is a valid path to your Rails app.

Now start up the Rails app:

$ foreman start

Our application should start and we can hit the homepage now. Navigate to https://demo.docker.localdev


We already have a simple model, so navigate to https://demo.docker.localdev/things

Create a few records, perform a few edits, destroy some things. Just make sure you make at least 10 or so requests.

This proves we have database connectivity.


To ensure we have cache connectivity, open a Rails console and do the following:

$ rails c
>> 'docker-demo'
=> nil
>> Rails.cache.write 'docker-demo', 'rocks!'
=> 288230376151711744
>> 'docker-demo'
=> "rocks!"
>> Rails.cache.clear
=> [true]
>> 'docker-demo'
=> nil

Cache is good!


Navigate to https://demo.docker.localdev/jobs/busy

Enable live polling and you should see a test job being executed every 10 seconds.

Redis is good!

Unified logs

Navigate to

Let Kibana load. In the “Index name or pattern” form field, change logstash.* to filebeat.* and click “Create”:


Click on “Discover”. Add a few fields. You have just setup awesome unified logs in Elasticsearch!


Points of interest

There are a couple of things I have done in this otherwise vanilla Rails app which allow for all this to happen.

  1. I bind the Rails server (puma) to port See the Procfile. This matches the port we use in the setup step, when we create an alias to
  2. I’ve added the lograge gem with some additional configuration in the config/development.rb file.
  3. I run a filebeat process which handles log forwarding to Elasticsearch.

Other than binding to the port described in [1], the Rails app has no knowledge of the fact that the underlying stack is running in Docker containers.

Go to Step 5: Gotchas and final thoughts


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s