Real-world Rails development with Docker (Part 1)

TL;DR

This series of articles shows how to setup a real-world development environment using Docker, Rails, Nginx, Elasticsearch, Memcached, Postgres and Redis.

There are also 2 supporting GitHub repos with fully-functional source code.

Series Index

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

Introduction

I know what you’re thinking… not another blog post about this stuff. Hang on there friend! Before you leave, let me describe my initial requirements:

  1. I have multiple Rails apps that access a shared database.
  2. My apps need access to a shared cache (Memcached).
  3. My apps need access to a shared Redis instance.
  4. My apps need access to a shared Elasticsearch instance.
  5. I want Nginx to serve as a reverse-proxy for all my apps.
  6. I want to access my apps with urls, not localhost:3000
  7. I want to use SSL with self-signed certificates.
  8. I want unified logs via Elasticsearch.

In addition to all this, I work on several different stacks, each with their own requirements: database types/versions, specific Elasticsearch versions, etc.

Note that I said stacks and not apps. Setting up a Docker development environment for a single, isolated application is fairly easy and there are already hundreds of blog posts showing you how to do this. I needed something much more robust and flexible.

Source code

There are 2 source code repos that support this series:

1. docker-demo-stack: This repo will control the Docker side of things.
2. docker-demo-app: This is a demo Rails app to illustrate how it all works.

Justification for this series

There are literally hundreds of blog posts detailing how to setup a development environment with Docker. Ruby, PHP, Node, whatever. Some are very good, but I have yet to find a single source of information that provided me with a comprehensive how-to guide to setup what I really needed – and wanted.

I spent many, many hours trying things out but none of the suggested solutions ticked all my boxes. In every article I read there was always a deal-breaker for me.

As I alluded to earlier, I work on a complex platform which consists of multiple Rails applications (7 and counting!). Sometimes I need to have all the apps running, sometimes only 2 of them, sometimes only a single one. The apps need to talk to each other, sometimes via http, sometimes via Redis. You get the picture…

This is fairly easy to setup if you install everything onto your host machine i.e. without Docker. However, you are then locked into specific versions and you have a myriad of services and software polluting your host.

Hello Docker.

Go to Part 2: Setup

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s